zaydek / retro-legacy

[WIP] Your friendly neighborhood React static-site generator
MIT License
2 stars 0 forks source link

[Defer] Implement simple client-side router, connoted by .render.* #31

Open zaydek opened 3 years ago

zaydek commented 3 years ago

In order to support .csr we need to be able to conditionally call ReactDOM.hydrate, which means we probably need to build a map and then based on something like if (process.env.NODE_ENV === "development" || !routes[window.location.pathname]) {, hydrate or render.

This should be fine because that client script shouldn’t run on the server. At least it worked before. I think this will work because we only call the renderToString, etc. functions for pages, not for the top-level app this is the invisible routing component). See #2 for some previous exploration.

zaydek commented 3 years ago

This is a very good idea that would benefit from implementing or pulling in a dynamic router.

Dynamic routers are not technically that hard or even hard to test. We can probably get away with implementing our own dynamic router as an extension or side-by-side package with the existing router package. So for example, maybe router/client or client-router? Doesn’t matter too much which one is used.

The idea is that pages are already .hydate by default, whereas .render provides a more traditional architecture. So for example, .hydrate and .render. I like this since it reuses the existing language with React; ReactDOM.hydrate and ReactDOM.render, where hydrate is implicit.