typesafe-i18n-demo-sveltekit icon indicating copy to clipboard operation
typesafe-i18n-demo-sveltekit copied to clipboard

Hooks.server.js and Layout.server.js runs multiple times

Open ulvidamirli opened this issue 2 years ago • 1 comments

Hooks.server.js and Layout.server.js runs multiple times instead of once. How can I solve it?

I use the latest version of Sveltekit and typesafe-i18n.

ulvidamirli avatar Sep 14 '22 21:09 ulvidamirli

As far as I know hooks.ts will run on each request.

Regarding +layout.server.ts, please take a look at the official SvelteKit docs: https://kit.svelte.dev/docs/load#invalidation.

I would assume you can prevent this by removing those lines: https://github.com/ivanhofer/typesafe-i18n-demo-sveltekit/blob/main/src/routes/%2Blayout.ts#L12-L14

Maybe you can also prevent this with the depends function: https://kit.svelte.dev/docs/load#input-methods-depends You would need to test this out as I haven't used it yet.

ivanhofer avatar Sep 15 '22 06:09 ivanhofer

Is this related to the issue? https://github.com/sveltejs/kit/issues/6854 or https://github.com/sveltejs/kit/issues/6800 If so, the problem belongs to Sveltekit.

taishi55 avatar Sep 19 '22 22:09 taishi55

I would assume it is a SvelteKit problem, since typesafe-i18n does not make any network calls.

ivanhofer avatar Sep 20 '22 05:09 ivanhofer