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

SvelteKit: when using with node-adapter, build and preview cause layout shift #437

Open
xmlking opened this issue Dec 27, 2022 · 5 comments

Comments

@xmlking
Copy link

xmlking commented Dec 27, 2022

After the build, when we run preview i.e., pnpm preview:
which activates service worker, script URLs change from full URL http://localhost:4173/auth/_app/immutable/assets/_layout-e564fd4d.css" to relative ./_app/immutable/assets/_layout-e564fd4d.css`

This causes the URL fetch to fail as the asset base path is wrong.

To Reproduce : https://github.com/xmlking/svelte-starter-kit

Before SW activation

image

After SW activation

image

Error in console

image

@xmlking xmlking changed the title SvelteKit: docker build or preview fail as assect SvelteKit: docker build or preview fail as asset URL changes Dec 27, 2022
@userquin
Copy link
Member

userquin commented Dec 27, 2022

@xmlking what build are you using? All pages generated without any script, and cannot register sw (build + preview)...

@xmlking
Copy link
Author

xmlking commented Dec 27, 2022

in
https://github.com/xmlking/svelte-starter-kit

pnpm node:build
# this generate ./build
pnpm preview 

@xmlking
Copy link
Author

xmlking commented Dec 27, 2022

I created this minimal repo to reproduce the issue https://github.com/xmlking/SPA-aaa-sveltekit-node-vite-pwa-issue

Steps to reproduce

  1. gh repo clone xmlking/SPA-aaa-sveltekit-node-vite-pwa-issue
  2. pnpm i
  3. pnpm build
  4. pnpm preview
  5. open http://localhost:4173/ and wait for SW Registered in console
  6. navigate to HELLO tab http://localhost:4173/demo/hello
  7. when you reload this page (browser refresh) you will see layout shifted page and errors in console log

image

image

Server side errors

Error: Not found: /demo/_app/immutable/assets/_layout-8454f68e.css
    at resolve (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2712:18)
    at resolve (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2599:34)
    at options.hooks.handle (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2829:59)
    at respond (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2597:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Error: Not found: /demo/_app/immutable/assets/ReloadPrompt-8b6f04a5.css
    at resolve (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2712:18)
    at resolve (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2599:34)
    at options.hooks.handle (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2829:59)
    at respond (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2597:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Error: Not found: /demo/_app/immutable/assets/_page-265a38f0.css
    at resolve (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2712:18)
    at resolve (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2599:34)
    at options.hooks.handle (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2829:59)
    at respond (file:///Users/schintha/Developer/Work/SPA/aaa/sveltekit-node-vite-pwa-issue/.svelte-kit/output/server/index.js:2597:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Now disable SvelteKitPWA adding disable: true

SvelteKitPWA({
	disable: true,
        ...
})

repeat the above steps, when you hard reload http://localhost:4173/demo/hello, you won't see the layout shift problem.

@xmlking xmlking changed the title SvelteKit: docker build or preview fail as asset URL changes SvelteKit: when using with node-adapter, build and preview cause layout shift Dec 27, 2022
@xmlking
Copy link
Author

xmlking commented Dec 27, 2022

for routers in root http://localhost:4173/ there is no problem as assets are relative to root.
but this is the only problem for sub routers e.g., http://localhost:4173/demo/hello as there are no assets relative to demo path

@austerj
Copy link

austerj commented Sep 21, 2023

Hi @xmlking, did you end up finding a solution for this? I'm having the same issue using the SvelteKit plugin. Also mentioned here: vite-pwa/sveltekit#24.

Edit: Seems to be fixed by setting paths: { relative: false } in svelte.config.js (vite-pwa/sveltekit#24 (comment)).

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

No branches or pull requests

3 participants