Replies: 2 comments 2 replies
-
I've actually managed to fix the issue that trying to rename the collection to the same forbidden name as the last time didn't error again. It was just me being dumb and searching for the issue at the completely wrong place. I just didn't retrigger the |
Beta Was this translation helpful? Give feedback.
-
Hi Vulcagon, The behavior you're seeing with In SvelteKit, the The key phrase here is "until the next update." When you trigger different actions like Here's why this happens:
The reason your TypeScript type checker suggests To fix this issue in your code, you should:
const { data, form } = $props();
// Handle both null and undefined cases
if (form === null || form === undefined) {
// Handle the case
}
This is one of those cases where the runtime behavior doesn't perfectly match what the TypeScript types suggest, which is why you're seeing this discrepancy. Hope this helps explain the behavior you're seeing! |
Beta Was this translation helpful? Give feedback.
-
I'm making a small website where you can create your own collections of something. I'm not an experienced web developer at all, it's actually my first website. I tried to work with
form
s and handle errors on submission. I followed the tutorials on the svelte website onform
s.Every collection needs to have it's own unique name so an error should be displayed if you try to rename a collection to an already existing name. The collection's name is also used in the URL part to get to the collection. My
+page.server.ts
file in the[collection]
folder looks something like the following. You can't only rename the collection you can also add or remove items from the collection but those are just functions returningPromise<void>
with no error handling at all. I'm usingPostgreSQL
as my database and thepostgres
npm package to communicate to my database.renameCollection
from$lib/server/db.js
takes the collection name that should be renamed as first argument and the new name as second argument and doesn't return anything.When now accessing
form
from$props
in my+page.svelte
file (const { data, form } = $props()
)form
should always be of typeActionData
, in my case of type{ error: string } | null
but neverundefined
. Inspectingform
with$inspect(form)
also tells me that initiallyfrom
isnull
and when trying to rename my collection to an already existing nameform
gets updated to{ error: string }
as expected (I'm usingenhance
from$app/forms
to prevent a full page reload). But if I now trigger a differentaction
likeadd
orremove
form
gets updated tonull
and then immediately toundefined
. While it's strange in the first place thatform
ever becomesundefined
it's not hard to make my code also handle the case whereform
isundefined
. But if I now trigger arename
with the exact same already existing nameform
doesn't get updated at all and staysundefined
. Only if I triggerrename
with another already existing nameform
gets updated to{ error: string }
again. I'm not sure why this is the case but I have the feeling it has something to do withform
ever gettingundefined
which should never happen in the first place. Is it because I have another+page.ts
file which triggers in between, after+page.server.ts
before+page.svelte
gets the newform
value? Or is it just a problem of my browser (I'm using Zen which is built on top of FireFox)? I just can't figure out why I don't get the same error again when trying to rename a collection to the same forbidden name which is pretty frustrating.Thank you all for trying to help me.
Beta Was this translation helpful? Give feedback.
All reactions