-
Notifications
You must be signed in to change notification settings - Fork 596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Immutable state on SSR (toString) #649
Conversation
40f4b45
to
e8fd0f1
Compare
e8fd0f1
to
2f9b25f
Compare
2f9b25f
to
f95f8e0
Compare
* master: 6.13.3 Revert init order change Add browser tests (choojs#696) 6.13.2 Fix location missing on store init (choojs#695) Typo Fix in Readme (choojs#693) 6.13.1 Fix wrong this usage in nanohref integration (choojs#689) Some spelling & typo fixes in readme (choojs#688) Fix inspect script (choojs#654)
* master: Update nanorouter (choojs#701) Use Object.assign instead of xtend (choojs#616)
LGTM. Any weird edge cases or anomalies this could cause for people upgrading that we need to mention in a breaking change log? |
The only real world effect it would have is for people and frameworks doing SSR and then plucking out e.g. var html = app.toString('/', state)
- var title = app.state.title
+ var title = state.title The only other thing I can think of is that stores will now only have their event listeners triggered once per event (as opposed to accumulating listeners for each |
* master: Match route before init stores (choojs#698) more timings (choojs#578) Disable hash routing by default (choojs#699)
This PR solves state leaking between calls to
toString
and race conditions that occur during double render pass (bankai et al.).The issue is that each call to
toString
would extendapp.state
, adding on more and more data for each render. If one was to expose the resultingapp.state
aswindow.initalState
one would get the combined state from all prior calls totoString
.It is especially troublesome during double render pass (calling
toString
twice, once to allow events to trigger data being fetched and another to render the view with fetched data). If two attempts at a double render pass are issued in quick succession (e.g. server responding to several requests), both calls will mutateapp.state
and the first to finish will get the intermediate state of both render calls.This PR ensures that the state passed into
toString
is only modified during that one pass through and thatapp.state
remains untouched.This would also allow us to proceed with choojs/bankai#446
Edit: Yet another issue solved by this PR is that every call to
toString
would initialize all stores and hence, add all listeners to the event bus over and over again for every render. This means that after a couple of renders any event listeners that e.g. fetches data will be fetching the same data several times over on every call totoString
.