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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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
forms and handle errors on submission. I followed the tutorials on the svelte website onforms.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.tsfile 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 usingPostgreSQLas my database and thepostgresnpm package to communicate to my database.renameCollectionfrom$lib/server/db.jstakes 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
formfrom$propsin my+page.sveltefile (const { data, form } = $props())formshould always be of typeActionData, in my case of type{ error: string } | nullbut neverundefined. Inspectingformwith$inspect(form)also tells me that initiallyfromisnulland when trying to rename my collection to an already existing nameformgets updated to{ error: string }as expected (I'm usingenhancefrom$app/formsto prevent a full page reload). But if I now trigger a differentactionlikeaddorremoveformgets updated tonulland then immediately toundefined. While it's strange in the first place thatformever becomesundefinedit's not hard to make my code also handle the case whereformisundefined. But if I now trigger arenamewith the exact same already existing nameformdoesn't get updated at all and staysundefined. Only if I triggerrenamewith another already existing nameformgets updated to{ error: string }again. I'm not sure why this is the case but I have the feeling it has something to do withformever gettingundefinedwhich should never happen in the first place. Is it because I have another+page.tsfile which triggers in between, after+page.server.tsbefore+page.sveltegets the newformvalue? 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