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

goto self can incorrectly result in 404 #4316

Closed
moatra opened this issue Mar 13, 2022 · 0 comments · Fixed by #4318
Closed

goto self can incorrectly result in 404 #4316

moatra opened this issue Mar 13, 2022 · 0 comments · Fixed by #4318

Comments

@moatra
Copy link
Contributor

moatra commented Mar 13, 2022

Describe the bug

If a page uses goto() to redirect to itself (say, to change a query parameter), and if the page has a ghost POST endpoint but no ghost GET endpoint, goto will result in displaying a 404 error page.

Reproduction

  1. Clone https://github.com/moatra/missing_get_redirect
  2. npm install
  3. npm run dev
  4. Open localhost:3000 in a browser.
  5. With javascript enabled, click "Submit Me". (exercises client-side goto)
    • Expected: Page updates appropriately
    • Actual: 404 error page
  6. With javascript disabled, click "Submit Me" (exercises normal http redirect)
    • Expected: Page updates appropriately
    • Actual page updates appropriately

Logs

Browser Request Logs
----------------------
POST http://localhost:3000/ [HTTP/1.1 200 OK 3ms]
GET http://localhost:3000/index.svelte?t=1647132611566 [HTTP/1.1 304 Not Modified 1 ms]
GET http://localhost:3000/__data.json?submitted [HTTP/1.1 404 Not Found 4ms]

Error Page Output:
----------------------
Failed to load data

load_route@http://localhost:3000/@fs/home/thomas/Projects/sveltekit_repros/missing_get_redirect/.svelte-kit/runtime/client/start.js:885:16
async*get_navigation_result@http://localhost:3000/@fs/home/thomas/Projects/sveltekit_repros/missing_get_redirect/.svelte-kit/runtime/client/start.js:603:25
update@http://localhost:3000/@fs/home/thomas/Projects/sveltekit_repros/missing_get_redirect/.svelte-kit/runtime/client/start.js:428:33
navigate@http://localhost:3000/@fs/home/thomas/Projects/sveltekit_repros/missing_get_redirect/.svelte-kit/runtime/client/start.js:1117:9
goto@http://localhost:3000/@fs/home/thomas/Projects/sveltekit_repros/missing_get_redirect/.svelte-kit/runtime/client/start.js:389:11
goto@http://localhost:3000/@fs/home/thomas/Projects/sveltekit_repros/missing_get_redirect/.svelte-kit/runtime/client/start.js:1180:34
on_submit@http://localhost:3000/src/routes/_enhance.js:15:13
async*form_enhance@http://localhost:3000/src/routes/_enhance.js:17:10
mount@http://localhost:3000/src/routes/index.svelte:135:67
createProxiedComponent/instrument/targetCmp.$$.fragment.m@http://localhost:3000/node_modules/svelte-hmr/runtime/svelte-hooks.js:291:25
mount_component@http://localhost:3000/node_modules/.vite/chunk-MHSN3BS3.js?v=e363d3f8:1626:24
mount@http://localhost:3000/.svelte-kit/generated/root.svelte:275:20
mount@http://localhost:3000/.svelte-kit/generated/root.svelte:564:40
mount@http://localhost:3000/.svelte-kit/runtime/components/layout.svelte:32:18
createProxiedComponent/instrument/targetCmp.$$.fragment.m@http://localhost:3000/node_modules/svelte-hmr/runtime/svelte-hooks.js:291:25
mount_component@http://localhost:3000/node_modules/.vite/chunk-MHSN3BS3.js?v=e363d3f8:1626:24
mount@http://localhost:3000/.svelte-kit/generated/root.svelte:174:20
mount@http://localhost:3000/.svelte-kit/generated/root.svelte:760:40
mount_component@http://localhost:3000/node_modules/.vite/chunk-MHSN3BS3.js?v=e363d3f8:1626:24
init@http://localhost:3000/node_modules/.vite/chunk-MHSN3BS3.js?v=e363d3f8:1705:20
Root@http://localhost:3000/.svelte-kit/generated/root.svelte:920:7
createProxiedComponent@http://localhost:3000/node_modules/svelte-hmr/runtime/svelte-hooks.js:341:9
ProxyComponent@http://localhost:3000/node_modules/svelte-hmr/runtime/proxy.js:242:29
Proxy<Root>@http://localhost:3000/node_modules/svelte-hmr/runtime/proxy.js:349:11
initialize@http://localhost:3000/@fs/home/thomas/Projects/sveltekit_repros/missing_get_redirect/.svelte-kit/runtime/client/start.js:564:10
_hydrate@http://localhost:3000/@fs/home/thomas/Projects/sveltekit_repros/missing_get_redirect/.svelte-kit/runtime/client/start.js:1475:14
async*start@http://localhost:3000/@fs/home/thomas/Projects/sveltekit_repros/missing_get_redirect/.svelte-kit/runtime/client/start.js:1511:16
@http://localhost:3000/:25:8

System Info

❯ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"

  System:
    OS: Linux 5.15 Fedora Linux 35 (Workstation Edition)
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 21.54 GB / 31.33 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 16.13.0 - /usr/bin/node
    npm: 8.1.0 - /usr/bin/npm
  Browsers:
    Firefox: 96.0
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.31 
    @sveltejs/kit: next => 1.0.0-next.295 
    svelte: ^3.44.0 => 3.46.4

Severity

serious, but I can work around it

Additional Information

Workaround is to provide a GET endpoint that returns a 200 response, but that seems to be an unnecessary network request.

Rich-Harris added a commit that referenced this issue Mar 14, 2022
* fix:  last match route  fallthrough return 404

* fix

* make test relate more directly to the missing method

* remove renamed test files

* lint

Co-authored-by: tom <anytable@gmail.com>
Co-authored-by: Rich Harris <hello@rich-harris.dev>
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 a pull request may close this issue.

1 participant