Don't use global router instance for SSR #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @lyohaplotinka,
As a follow-up, I was able to get SSR running eventually - the component module signatures for SSR are different, and I was expecting a specific kind in order to hook everything up.
However, I started to notice an unexpected side-effect of
global.$$$easyrouteRouter
being a router instance.Since I had implemented some of my own
beforeLeave
hooks (as shown in the Sandbox.io demo I sent you by email), I saw how SSR requests were suddenly 'stateful':beforeLeave
was triggered with the last visited url, even though the server should not actually be aware of this (as it could have been any request, not just mine).In cases like this, it's always better to opt for a 'shared-none' approach, and solely operate within the boundary of a single request. As such, one should create a new router for every request - perhaps some optimizations can be made within
easyroute-core
which only recreates the 'history' for SSR (or better yet: doesn't keep anything stateful around).Please have a look at the code. My solution piggy-backs on the current
global.$$$easyrouteRouter
but only to get the factory function that creates the router on each request. I'm sure there are better ways, but it's only to give you a general idea.