Skip to content
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

Eliminate a frameback navigation initialization race #518

Merged
merged 1 commit into from
Aug 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/react-server/core/FramebackController.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,15 @@ class FramebackController extends EventEmitter {
// If the frame has a client controller we'll listen to when
// _it_ tells us it's done loading.
//
if (clientController && !clientController.__parentIsListening) {
clientController.__parentIsListening = true;
clientController.context.onLoadComplete(this._handleFrameLoad.bind(this, frame));
}

// It may have finished _before_ we get here, so we'll also check
// whether it has already set its `_previouslyRendered` flag.
//
if (clientController && !clientController.__parentIsListening && !clientController._previouslyRendered) {
clientController.__parentIsListening = true;
clientController.context.onLoadComplete(this._handleFrameLoad.bind(this, frame));
if (clientController && !clientController._previouslyRendered) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an else if block? or even an else block? clientController.__parentIsListening is set on the first load, as is clientController._previouslyRendered -- are the two separate checks because there's asynchrony and users may perform navigations before we've finished loading?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an else if block? or even an else block?

It can't, actually. You'll notice that previously the bodies of the two cases were together, and the conditionals were anded. In the case where the frame's load event fires before the client controller finishes rendering we still need both to happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically: We always need to wire up our listener (once). And, in the case where the event we're listening to hasn't fired yet, we'll bail out early and wait for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's asynchrony and users may perform navigations before we've finished loading?

It's actually just a race between the browser's load event and the client controller finishing its render. No user interaction needed.

return;
}

Expand Down