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

optimise builds for hash router apps #13217

Open
Rich-Harris opened this issue Dec 21, 2024 · 5 comments
Open

optimise builds for hash router apps #13217

Rich-Harris opened this issue Dec 21, 2024 · 5 comments
Labels
feature / enhancement New feature or request

Comments

@Rich-Harris
Copy link
Member

Rich-Harris commented Dec 21, 2024

Describe the problem

If router.type === 'hash' we don't need to create a server manifest or bundle routes etc

@Rich-Harris Rich-Harris added the feature / enhancement New feature or request label Dec 21, 2024
@gevera
Copy link

gevera commented Dec 27, 2024

Hey, @Rich-Harris

Sveltekit throws an error on build when using hash router and setting in +layout.ts export const ssr = false;

node:internal/event_target:1094
  process.nextTick(() => { throw err; });
                           ^
Error: Page options are ignored when `router.type === 'hash'` (src/routes/+layout.ts has 'ssr')
    at analyse (file:///home/nixos/Projects/bobr/tg_quiz_mini_app/client/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:81:11)
    at async MessagePort.<anonymous> (file:///home/nixos/Projects/bobr/tg_quiz_mini_app/client/node_modules/@sveltejs/kit/src/utils/fork.js:23:16)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)

Node.js v20.17.0

It makes sense we do not need to set the ssr to false since the hash type of the sveltekit router will do it automatically for us.
Besides, the SPA section in the docs don't seem to mention this.

Should I create another issue regarding this?

@gevera
Copy link

gevera commented Jan 1, 2025

Also, an intersing thing is that when using hash router, the url searchParams are not detected
Here is an example

image

In my case after importing page from $app/state page.url.searchParams.get('question') should return some_question_id

@7nik
Copy link

7nik commented Jan 2, 2025

Also, an intersing thing is that when using hash router, the url searchParams are not detected

It was decided that users should use the real search params:
/#/quiz/some_quiz_id?question=some_question_id → /?question=some_question_id#/quiz/some_quiz_id

@chrisvire
Copy link

chrisvire commented Jan 3, 2025

@Rich-Harris, @gevera:

I am producing a PWA, so I think I want SSR = false. I want to use hash-based routing since I will be publishing multiple copies of the PWA (based on content in hundreds of minority languages -- each with its own PWA).
#7443 (comment)

If I use hash-based routing, is SSR assumed? I have to remove export const ssr = false; from my /src/routes/+layout.js file for hash-based routing to work. If I leave it in, I get the error that @gevera got:

node:internal/event_target:1083
  process.nextTick(() => { throw err; });
                           ^
Error: Page options are ignored when `router.type === 'hash'` (src/routes/+layout.js has 'ssr')
    at analyse (file:///Users/hubbard/codereview/appbuilder-pwa/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:81:11)
    at async MessagePort.<anonymous> (file:///Users/hubbard/codereview/appbuilder-pwa/node_modules/@sveltejs/kit/src/utils/fork.js:23:16)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

Shouldn't there be a configuration-based way to specify this (in svelte.config.js)?

Update: I just found in the docs.

'hash' means the route is determined by location.hash. In this case, SSR and prerendering are disabled.

@lumosminima
Copy link

Also, an intersing thing is that when using hash router, the url searchParams are not detected

It was decided that users should use the real search params: /#/quiz/some_quiz_id?question=some_question_id → /?question=some_question_id#/quiz/some_quiz_id

This feels weird.

Old 🔥
https://ui.home.arpa/spaces/019400fb-6162-71d8-9d7c-e4ee053c8a32/accounts?type=liability&groupBy=tags

New 😅
https://ui.home.arpa/?type=liability&groupBy=tags#/spaces/019400fb-6162-71d8-9d7c-e4ee053c8a32/accounts

I use goto() for filtering and it broke my previous logic and I had to prepend the query:

goto( `${resolveRoute(`/?${this.query.toString()}#/(app)/spaces/[id]`, { id: spaceId.current })}/accounts`, {
	        replaceState: true,
	        keepFocus: true,
	    }
	);

Wouldn't it have been better to add special handling when in hash mode so we didn't have to refactor when moving between hash and standard routing? That way it would have worked in both modes seamlessly. Even if my URL was ugly before due to uuid it still had meaning but now it looses that and feels different from all other URLs on internet. I think both prepended ?query and appended query should work. I can of course handle it on my own but this is precisely why I use frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants