Prevented Link Double Render in React #79
Merged
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.
The forceUpdate in the onNavigate handler caused an unnecessary re-render. Immediately after a Link component renders the onNavigate handler fires which causes a re-render even though nothing's changed.
ReactDOM.render is synchronous only if mounting a brand new component. When ReactDOM.render is async then the unnecessary re-render doesn't happen because the onNavigate fires before the first render and so React squashes the two render requests into one.
Changed the Link components to store the state context url in React state each time they render. Then the onNavigate handler only re-renders if the the state context url has changed since previous render.
The Back Link stores the crumb as well as the url in state because the crumb can change even when the context url doesn't (with a custom truncate crumb trail). Accessing the crumb is cheap because it's not evaluated each time, it's just take from the cached crumbs.
Didn't implement this in knockout or angular because the Links update so often it didn't seem worth it.