You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, thanks for pointing this out @ldlac. I definitely need better docs here, but views are server-side rendered with V8, the hydrated on the client, so your top-level statements in Svelte have the same restrictions as you would have in SvelteKit, Next.js, etc.
The difference is that they use Node.js to do SSR, so it has things like setInterval, while Bud uses V8. So TL;DR:
localStorage, window, document cannot be used top-level right now and no plans currently to support them. Your views need to work outside of the browser environment for the initial render 1
setInterval: should be supported. Getting this working should be pretty easy thanks to this excellent library which looks like it has an interval library.
Footnotes
I have thought about adding a minimal DOM implementation to V8 via https://www.npmjs.com/package/undom. I'm not sure if this is a good idea though because it may hide errors. At the same time it would be quite a bit more convenient for people that understand what's happening, you wouldn't need to wrap your addEventListener in a typeof document != undefined for example. ↩
matthewmueller
changed the title
setInterval and other browser APIs are not defined
Support setIntervalJun 5, 2022
Not sure if it's related but
localStorage
,window
,document
,setInterval
, etc have a weird behavior too.when wrapped inside a
if (typeof document != "undefined")
or anything that v8 will appreciate, everything is fine,console.log
includedOriginally posted by @ldlac in #87 (comment)
The text was updated successfully, but these errors were encountered: