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

Navigating to an API handler route 404's in logs. #13195

Open
Mardoxx opened this issue Dec 18, 2024 · 2 comments
Open

Navigating to an API handler route 404's in logs. #13195

Mardoxx opened this issue Dec 18, 2024 · 2 comments
Labels
needs-decision Not sure if we want to do this yet, also design work needed

Comments

@Mardoxx
Copy link

Mardoxx commented Dec 18, 2024

Describe the bug

Navigating to an API only route yields a 404 in the console. If we do a redirect inside the api route to the app, it does not update the URL correctly.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-ipxflmtx

  1. Open dev console
  2. Click the red link
  3. Witness error in console
  4. Observe URL bar is not at the correct route (/moonlight)

Logs

Error: Not found: /out_there
    SvelteKitError control.js:45
    navigate client.js:1312
    _start_router client.js:2175
    _start_router client.js:2066
    start client.js:314
    async* (index):212
    promise callback* (index):211
[email protected]:26:94631
    error [email protected]:26
    handleError app.js:18
    handle_error client.js:1642
    navigate client.js:1312
    _start_router client.js:2175
    _start_router client.js:2066
    start client.js:314
    <anonymous> (index):212
    (Async: promise callback)
    <anonymous> 


### System Info

```Shell
npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
Need to install the following packages:
[email protected]
Ok to proceed? (y) 
 
  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^3.3.1 => 3.3.1 
    @sveltejs/kit: ^2.12.1 => 2.12.1 
    svelte: ^5.14.4 => 5.14.4 
    vite: ^6.0.3 => 6.0.3 


### Severity

blocking all usage of SvelteKit
@Mardoxx
Copy link
Author

Mardoxx commented Dec 18, 2024

See also #10855 with form actions at API only routes and use:enhance

@eltigerchino eltigerchino closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2024
@eltigerchino eltigerchino reopened this Dec 19, 2024
@eltigerchino
Copy link
Member

eltigerchino commented Dec 19, 2024

I think this is a separate issue from #10855

Essentially, our client router is reporting a 404 because API handlers are not part of the navigable routes list (only pages are). The end result is that we perform a native navigation to the API handler URL and end up being redirected correctly anyway so I think it's fine?

Ideally, a 404 isn't logged since the API handler route is our own. However, I'm not sure it's worth sending that extra information to the client.

A workaround for now is to add data-sveltekit-reload to links that navigate to the API handler route so that it skips trying to find a matching page and won't log a 404. https://svelte.dev/docs/kit/link-options#data-sveltekit-reload

@eltigerchino eltigerchino added the needs-decision Not sure if we want to do this yet, also design work needed label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Not sure if we want to do this yet, also design work needed
Projects
None yet
Development

No branches or pull requests

2 participants