I'm attempting to write a component that can update my user's history so they can easily deep-link to a set of filter settings as they update the settings. What's the best way to write client-only code that relies on window being available?
Nevermind, I've figured out how to get this to work without erroring out. Sapper includes process.browser for client-rendered code. I've wrapped my browser-only code in a check for if(process.browser === true), and all is well
Also, any code inside component lifecycle hooks (oncreate and ondestroy) or any methods will only run on the client
@Rich-Harris are there any hooks like oncreate/ondestroy that will run only on server side?
@jakubsacha it's better to open a new issue and link to any old issues when you're asking something new. For general support questions maybe the Discord chatroom or Stack Overflow are a better choice.
The oncreate and ondestroy are runtime only and don't make sense at all in a SSR senario. Maybe <script context="module"> could be useful in your case? See:
Most helpful comment
Also, any code inside component lifecycle hooks (
oncreateandondestroy) or anymethodswill only run on the client