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

TypeError when updating $session in component constructor #1658

Closed
sfriedel opened this issue Jun 9, 2021 · 3 comments · Fixed by #1691
Closed

TypeError when updating $session in component constructor #1658

sfriedel opened this issue Jun 9, 2021 · 3 comments · Fixed by #1691

Comments

@sfriedel
Copy link

sfriedel commented Jun 9, 2021

Describe the bug
If the $session store gets written to in the component constructor of a route, sveltekit throws a TypeError at https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/client/renderer.js#L115

Logs

start.js:448 Uncaught (in promise) TypeError: Cannot read property 'parse' of null

To Reproduce

  • git clone -b typeerror-during-session-hydration [email protected]:sfriedel/sveltekit-bugreport.git
  • pnpm install
  • pnpm dev
  • open http://localhost:3000/ in the browser
  • you should see the exception from above in the JS error logs
  • check src/routes/index.svelte for the code that triggers the error

Expected behavior
No exception should be thrown

Stacktraces

Stack trace

start.js:448 Uncaught (in promise) TypeError: Cannot read property 'parse' of null
at Array. (start.js:448)
at Object.set (index.mjs?v=93707a36:35)
at set_store_value (index.mjs?v=93707a36:136)
at instance (index.svelte? [sm]:9)
at init (index.mjs?v=93707a36:1485)
at new Routes (index.svelte? [sm]:10)
at createProxiedComponent (svelte-hooks.js:245)
at new ProxyComponent (proxy.js:241)
at new Proxy (proxy.js:341)
at create_if_block_2 (root.svelte? [sm]:38)

Information about your SvelteKit Installation:

Diagnostics System: OS: Linux 5.8 Ubuntu 20.10 (Groovy Gorilla) CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz Memory: 1.31 GB / 15.34 GB Container: Yes Shell: 5.8 - /bin/zsh Binaries: Node: 14.17.0 - /usr/bin/node Yarn: 1.22.5 - /usr/bin/yarn npm: 6.14.13 - /usr/bin/npm Watchman: 4.9.0 - /home/sef/.local/opt/watchman/bin/watchman Browsers: Chrome: 90.0.4430.212 Firefox: 89.0 npmPackages: @sveltejs/kit: next => 1.0.0-next.115 svelte: ^3.34.0 => 3.38.2

Severity
Low. I have a workaround in place: deferring the store updates with a simple setTimeout(..., 0) seems to avoid the issue.

@gxcodes
Copy link

gxcodes commented Jun 10, 2021

Was about to write an issue but saw this. It happened on fresh init npm init svelte@next and choose skeleton. Import {session} and {browser} then set value to $session trigger the TypeError loking for url route.

Low. I have a workaround in place: deferring the store updates with a simple setTimeout(..., 0) seems to avoid the issue.

Thanks @sfriedel, confirmed also this workaround somehow worked: setTimeout(() => $session = ... )

@ajwinkworth
Copy link

I also have an issue with the same code but I am calling session.set() in a async click event handler after doing a fetch to an endpoint.

The setTimeout() workaround did not work for me. App still seems to function fine.

@benmccann
Copy link
Member

Posting a link to the reproduction repo here for ease of access: https://github.com/sfriedel/sveltekit-bugreport/tree/typeerror-during-session-hydration

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

Successfully merging a pull request may close this issue.

4 participants