Conversation
🦋 Changeset detectedLatest commit: f2cdab2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
You |
|
Tried the upgrade to 472 this morning got the following error. This is a large project with many routes. Also had problem with the last install script failing, but I was able to migrate successfully manually. The problem here is that the install fails and rolls-back to the previous build. Any suggestions? Error: Method overrides have been removed in favor of actions. See the PR for more information: #6469 |
|
How do you run the install? Just |
|
I ran pnpm I @sveltejs/kit@latest... My Package.json looks as follows: { |
|
@dummdidumm Thanks! I'll get working through them. |
|
@rowantrollope Check your |
|
FIXED! That was it. Thank you VERY much
Rowan
Sent via Superhuman ( ***@***.*** )
…On Tue, Sep 06, 2022 at 5:15 PM, twobitunicorn < ***@***.*** > wrote:
@ rowantrollope ( https://github.com/rowantrollope ) Check your svelte.config.js
and make sure you are no longer adding the method overrides for PATCH and DELETE
. The snippet below is possibly what you have if you have an older project
(as I did!).
// Override http methods
methodOverride: {
allowed: ['PATCH',
'DELETE']
}
—
Reply to this email directly, view it on GitHub (
#6469 (comment) ) , or unsubscribe
(
https://github.com/notifications/unsubscribe-auth/ACXKL5PJBFWHAGVVQHEU3Q3V47ND3ANCNFSM6AAAAAAQBN573Y
).
You are receiving this because you were mentioned. Message ID: <sveltejs/kit/pull/6469/c1238770516
@ github. com>
|
|
|
You can provide your own callback to the enhance action and set a variable to pending during fetching. When the return callback function is called you know the fetch is done. |
|
in docs in file:
Should we write?
|
Ooh, that likely explains why my experiments did not work as expected (and also #6611). I was wondering whether forms is typed automatically. Having seen the incredible typing magic by @dummdidumm I assume it is, and that's probably why we return validation errors instead of throwing them? |
This should be mentioned in the migration guide. |
|
Yes that was it, and that fixed it! Thanks
Sent via Superhuman iOS ( ***@***.*** )
…On Thu, Sep 8 2022 at 7:06 AM, vipero07 < ***@***.*** > wrote:
>
>
> @rowantrollope ( https://github.com/rowantrollope ) Check your svelte.config.js
> and make sure you are no longer adding the method overrides for PATCH and DELETE
> . The snippet below is possibly what you have if you have an older project
> (as I did!).
>
> // Override http methods
> methodOverride: {
> allowed: ['PATCH',
> 'DELETE']
> }
>
This should be mentioned in the migration guide.
—
Reply to this email directly, view it on GitHub (
#6469 (comment) ) , or unsubscribe
(
https://github.com/notifications/unsubscribe-auth/ACXKL5KPCKIZXKCNE5XSTWLV5HXE7ANCNFSM6AAAAAAQBN573Y
).
You are receiving this because you were mentioned. Message ID: <sveltejs/kit/pull/6469/c1240765956
@ github. com>
|
|
So what about array-data inside my form? |
|
Ok, got it. FormData.getAll(). |
|
Does |
|
Step 2 should import fail, not invalid |
|
May want to address JSON POST endpoints for the conversion guide? In my case I needed to use |
|
See #7494 for that, I added a note to the migration description |
How to migrate
The
POST/PUT/PATCH/DELETEmethods on+page.server.jsare replaced by anactionsobject.If you used those methods for form submissions
Step 0 (before updating)
Remove method overrides from your
svelte.config.js(they have been removed, see the other steps on how to migrate) - there have been reports that running npm install after bumping the version with this config still present fails.// svelte.config.js const config = { kit: { - methodOverride: { - allowed: ['PATCH', 'DELETE'] - } }Step 1
If you have more than one form on that page, think about names that best describe it and add these names as keys to the new action object inside
+page.server.js. Example:If you only have one form, you don't need to give it a name, use
default:Step 2
Move your methods over to the respective names of the actions object. Adjust the return value accordingly:
return { location: 'X' }withthrow redirect(303, 'X')return { status: 400, errors: errors }withreturn fail(400, errors)(return invalid(400, errors)if you are not migrating to the latest version of SvelteKit directly)The success response and invalid response both become available on
export let forms(see step 4 for more info).Step 3
Update your
<form>elements in+page.svelte(or components used by it), if you were previously usingPUT/PATCH/DELETEand are now using named actions:The
/editTodois a normal query parameter. SvelteKit interprets a query parameter with a leading/as identifying a named action.?/editTodowill call theeditTodoaction inexport const actions = { editTodo: ..., ... }Step 4
Replace
export let errorswithexport let formin+page.svelte:This will contain the return value of the action that just ran (as long as it didn't error or redirect), allowing you to show a 'success' message or (in the case of validation errors) fill in previously submitted values and indicate which fields were invalid.
Example:
This from the server..
... will become available on the component:
If you used those methods for something else
Either adjust your urls and only make POST requests with
FormDatato it, ot move these methods over to a+server.jsfile. We will very soon make it possible to colocate a+server.jsfile next to a+page.sveltefile. The return value needs to be aResponseobject; you can use thejsonhelper method to make creation of that easier.Manually making the fetch requests
use:enhanceshould do all of this for you. If you're on the latest version of SvelteKit and want to do it, see #7494 on how.PR description
Implements #5875
Closes #3533
TODO
export const actionsexport let errorsin favor ofexport let formPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0