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

Fragment URL issue using static-adapter #3228

Closed
JeremyMoeglich opened this issue Jan 7, 2022 · 6 comments · Fixed by #3251 or #3367
Closed

Fragment URL issue using static-adapter #3228

JeremyMoeglich opened this issue Jan 7, 2022 · 6 comments · Fixed by #3251 or #3367
Labels
bug Something isn't working p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. pkg:adapter-static

Comments

@JeremyMoeglich
Copy link
Contributor

Describe the bug

When you have something like this

├── routes
    ├── index.svelte
    └── test
        └── route.svelte

Route.svelte:

<a href="#something" id='something'>Text</a>

the page will see the URL as /test/route#something
adapter-static will check the wrong URL (/test) which doesn't exist,
Error: (404 /test (linked from /test/route))

adding an index.svelte fixes the issue, but you may not always want an index.svelte

├── routes
    ├── index.svelte
    └── test
        ├── index.svelte
        └── route.svelte

Reproduction

https://github.com/JeremyMoeglich/href-fragment-issue

npm install
npm run build

Logs

npm run build

> href-fragment-issue@0.0.1 build
> svelte-kit build

vite v2.7.10 building for production...
✓ 15 modules transformed.
.svelte-kit/output/client/_app/manifest.json                         1.47 KiB
.svelte-kit/output/client/_app/layout.svelte-091e4ac8.js             0.53 KiB / gzip: 0.35 KiB
.svelte-kit/output/client/_app/error.svelte-b6279998.js              1.56 KiB / gzip: 0.75 KiB
.svelte-kit/output/client/_app/pages/index.svelte-58aa7df0.js        0.70 KiB / gzip: 0.42 KiB
.svelte-kit/output/client/_app/pages/test/route.svelte-8aa31dfa.js   0.75 KiB / gzip: 0.44 KiB
.svelte-kit/output/client/_app/assets/start-61d1577b.css             0.16 KiB / gzip: 0.15 KiB
.svelte-kit/output/client/_app/start-e1e03bcc.js                     19.73 KiB / gzip: 6.81 KiB
.svelte-kit/output/client/_app/chunks/vendor-a7db36b2.js             7.07 KiB / gzip: 2.91 KiB
vite v2.7.10 building SSR bundle for production...
✓ 13 modules transformed.
.svelte-kit/output/server/manifest.json                        1.12 KiB
.svelte-kit/output/server/app.js                               46.60 KiB
.svelte-kit/output/server/entries/pages/layout.svelte.js       0.24 KiB
.svelte-kit/output/server/entries/pages/error.svelte.js        0.72 KiB
.svelte-kit/output/server/entries/pages/index.svelte.js        0.31 KiB
.svelte-kit/output/server/entries/pages/test/route.svelte.js   0.34 KiB
.svelte-kit/output/server/chunks/index-2dc61825.js             2.24 KiB

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-static
> 404 /test (linked from /test/route)
Error: 404 /test (linked from /test/route)
    at file:///C:/Users/jerem/Desktop/dev/Web/href-fragment-issue/node_modules/@sveltejs/kit/dist/chunks/index5.js:167:11
    at visit (file:///C:/Users/jerem/Desktop/dev/Web/href-fragment-issue/node_modules/@sveltejs/kit/dist/chunks/index5.js:326:5)

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
    Memory: 15.94 GB / 31.92 GB
  Binaries:
    Node: 17.2.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @sveltejs/adapter-static: ^1.0.0-next.24 => 1.0.0-next.24
    @sveltejs/kit: next => 1.0.0-next.216
    svelte: ^3.44.0 => 3.45.0

Severity

serious, but I can work around it

Additional Information

No response

@bluwy bluwy added bug Something isn't working p3-edge-case SvelteKit cannot be used in an uncommon way pkg:adapter-static labels Jan 7, 2022
@benmccann benmccann added p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. and removed p3-edge-case SvelteKit cannot be used in an uncommon way labels Jan 8, 2022
@bseib
Copy link

bseib commented Jan 15, 2022

This is also an issue for any relative path URLs, not just #fragment URLs. E.g.,

   <a href="/legitimate">Go to legit page outside Svelte</a>

I get an error 404 /legitimate (linked from /YourPage) when doing a static build (but only see it during the "server-side" phase of the build, which I don't think is needed for us...?).

For our use case, we have an existing website already using other frameworks. We're introducing svelte for some new static pages that will be served from the same site from a new dir. So we will be linking to existing relative URLs that Svelte doesn't produce itself or even know about.

Should I open a new issue? Or did I miss a way that this use case is handled?

@bseib
Copy link

bseib commented Jan 16, 2022

Or did I miss a way that this use case is handled?

Well, I just discovered rel=external. Sorry for the noise! 😄

@benmccann
Copy link
Member

this is broken again. I believe by #3288

@sharu725
Copy link

sharu725 commented Feb 25, 2022

> Using @sveltejs/adapter-static
> 404 /article/img/sample.png (linked from /article/svelte-kit-blog-demo)
    at file:///mnt/6d542572-76bb-43f4-8269-4e2d72741fb7/personal/node_modules/@sveltejs/kit/dist/chunks/index5.js:427:11
    at save (file:///mnt/6d542572-76bb-43f4-8269-4e2d72741fb7/personal/node_modules/@sveltejs/kit/dist/chunks/index5.js:659:4)
    at visit (file:///mnt/6d542572-76bb-43f4-8269-4e2d72741fb7/personal/node_modules/@sveltejs/kit/dist/chunks/index5.js:552:3)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

This seem to be broken again. I'm using the latest version of sveltekit.
The image is missing but I want the build to continue. Is there a way to ignore missing images in the build?

@geoffrich
Copy link
Member

@sharu725 I don't think that error is related to this issue, which was about fragment URLs. To customize SvelteKit's behavior when it encounters a broken link, you can pass a function to prerender.onError: https://kit.svelte.dev/docs/configuration#prerender.

@sharu725
Copy link

That solved my issue. Thank you @geoffrich 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. pkg:adapter-static
Projects
None yet
6 participants