Skip to content

feat: change zod schema for form validation in local persistence#11

Closed
csantosr wants to merge 1 commit intoMrRoiz:mainfrom
csantosr:feature/persistence
Closed

feat: change zod schema for form validation in local persistence#11
csantosr wants to merge 1 commit intoMrRoiz:mainfrom
csantosr:feature/persistence

Conversation

@csantosr
Copy link
Copy Markdown
Collaborator

New zod schema changing the .min and the .nonempty

@csantosr csantosr requested a review from MrRoiz January 28, 2026 13:40
@csantosr csantosr self-assigned this Jan 28, 2026
},
);

const LocalGameFormSchema = z.object({
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Maybe I'm wrong but doesnt the watch method return the right type of the form already?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. The watch return it as Partial. Meaning that each value can be undefined

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we can try add default values there instead of creating a new zod schema, or create a wrapper atom, that handles those undefined values
image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is updated

}
if (gameSettings.players.length >= MIN_PLAYERS) {
hasHydrated.current = true;
form.reset(gameSettings);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this what if we directly pass that value to the default values of the form?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a hydration timing problem. The first value that the atom takes when the component is mounted is the default value and then the localStorage is loaded. Meanwhile, useForm initializes on mount, having the empty default as its default values.

@csantosr csantosr force-pushed the feature/persistence branch from aaa71ac to 141d745 Compare February 3, 2026 22:35
@csantosr csantosr force-pushed the feature/persistence branch from 141d745 to c1265e1 Compare February 3, 2026 22:38
@MrRoiz
Copy link
Copy Markdown
Owner

MrRoiz commented Feb 22, 2026

Implemented tanstack form instead

@MrRoiz MrRoiz closed this Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants