fireship-io / fkit-course

The Full SvelteKit Course
175 stars 32 forks source link

formDefaults undesired mutation by setting a svelte store #5

Open christenbc opened 11 months ago

christenbc commented 11 months ago

https://github.com/fireship-io/fkit-course/blob/ce1b40a030c5461ba4e449a2c45eae6fdfcb4543/src/routes/%5Busername%5D/edit/%2Bpage.svelte#L24

bind:value={$formData.title}
bind:value={$formData.url}

For some reason, are mutating the original

const formDefaults = {
    icon: 'custom',
    title: '',
    url: 'https://'
};

this is an undesired behavior since

formData.set(formDefaults);

is setting the values to the previous once, hence the form is not being resetted.

What is going on?

christenbc commented 11 months ago

I tested Object.freeze(formDefaults); is trying to be violated.