-
-
Notifications
You must be signed in to change notification settings - Fork 2k
use undefined
instead of null
for empty form
prop
#7178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I just tested this in the Svelte REPL, changing this to |
You may use the relatively new JS/TS language feature "?": Every "?.*" junction will return |
Ah right, it will only set the default value on the first time. In my case I always return the same shape for error objects, so it will always be defined once I have submitted the form and the For now I will continue using this approach: <script>
export let form
$: form = form || { errors: { } }
</script> Can you please link me to the Svelte issue describing the behaviour you are referring to? |
Haven't found it so far, maybe the almighty @Conduitry knows, I believe he commented on that issue |
Moving this to post-1.0 (in other words, for consideration for 2.0). It's unclear by now if the behavior will be changed for Svelte 4 (although I would be in favor of it), and if it is, it would probably result in a hard-to-catch subtle change in behavior if it's possible to use SvelteKit 1.0 with Svelte 4. |
@dummdidumm Sorry, missed your comment from a few weeks ago. This was discussed in sveltejs/svelte#4442 and sveltejs/svelte#5673 but both of these are closed. I don't know that there is an open issue tracking this, and I'm not convinced that this is something we'd want to change anyway, even as a breaking change in Svelte 4. |
This behavior was also made explicit in the documentation, I'm now remembering, in sveltejs/svelte#4460. |
I think this conversation is moving in a different direction. My initial suggestion was to just use |
I'm not sure the change is worth it if we don't change the behavior in Svelte 5 for the fallback being applied everytime the value is |
I think we should punt on this until Svelte 5 is a bit more settled. We can revisit and make a final decision then. I'll move this to the 3.0 milestone for now |
Describe the problem
Using the new actions feature of SvelteKit, when loading the page the
form
prop is set tonull
. In my usecase I return anerrors
object if some of the form fields don't pass the validation in the action.To not having to deal with unnecessary
if
checks or optional chainings, I'm settingerrors
to an empty object when the page loads andform
is stillnull
.This works fine, if I only use the
errors
object in that file. But if I accidentially accessform
again, I'll get an error because form is stillnull
.To not having the issue above I would need to set the default value like this:
But this requires me to write additional code.
Describe the proposed solution
form
should beundefined
and notnull
to make it possible to set a fallback value like you would do in otherSvelte
components:Alternatives considered
Leave it as it is.
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: