Skip to content
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

[fix] make demo app work without JS #3965

Closed
wants to merge 1 commit into from

Conversation

geoffrich
Copy link
Member

Fixes #3952

After the introduction of shadow endpoints, the demo app would throw a "Body returned from shadow endpoint request handler must be a plain object" error when adding a todo with JS disabled. This was because we were returning a Response, not a POJO.

After fixing that issue, I also had to modify the request passed to the api in the get handler. When rendering a page in response to a POST, the get handler is called with a POST request. Since we passed the original request to the api method, we were sometimes making a POST request when we needed a GET. By making a new request, we make sure the method is GET in all cases. I added an explanatory comment to the code since it's a little weird.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Feb 16, 2022

🦋 Changeset detected

Latest commit: 81d31b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-svelte Patch

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

@geoffrich
Copy link
Member Author

As an aside, I didn't see the "call the GET handler after POST when rendering a page" behavior captured in the docs. Should it be?

@Conduitry
Copy link
Member

There's a code comment in https://kit.svelte.dev/docs/routing#endpoints-post-put-patch-delete of "The page always has access to props from get..." but that could maybe have a bit of a bigger deal made of it.

Rich-Harris added a commit that referenced this pull request Feb 16, 2022
@Rich-Harris Rich-Harris mentioned this pull request Feb 16, 2022
5 tasks
@Rich-Harris
Copy link
Member

I had some suggestions but it was easier to try them out and submit an alternative PR, rather than try to cram them into inline commit suggestions: #3970

@geoffrich
Copy link
Member Author

Closing in favor of #3970.

@geoffrich geoffrich closed this Feb 17, 2022
Rich-Harris added a commit that referenced this pull request Feb 17, 2022
* [fix] make demo app work without JS

* alternative approach to #3965

* actually

Co-authored-by: Geoff Rich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Demo App: Todo doesn't work without Javascript
3 participants