preactjs / preact-iso

Isomorphic utilities for Preact
MIT License
69 stars 9 forks source link

feat: Add `location` stub utility #28

Closed rschristian closed 3 months ago

rschristian commented 4 months ago

While a user can pass a url prop to LocationProvider (our types don't support this though), without this location stub, the router will not work during SSR as it unconditionally tries to access location.origin:

https://github.com/preactjs/preact-iso/blob/2398d3b824af7ff445bf9337082ad9ed523415b5/src/router.js#L72

I'm generally in favor of pushing the location stub anyhow, it's far more robust in allowing client-side libs to work properly, hence, making it available here for any using the router (but using their own SSR impl). I don't think passing the URL prop to components is a great pattern that we should fix or support really, but that's just me.