-
Notifications
You must be signed in to change notification settings - Fork 8
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
refactor: update to latest react version #39
base: main
Are you sure you want to change the base?
Conversation
…ype’ instead of ‘interface’.
buttonRef.current && | ||
containerRef.current && | ||
containerRef.current.lastChild === tempSpan | ||
) { | ||
render(tempSpan.appendChild(buttonRef.current), (el) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial state:
<span> <!-- containerRef-->
<a> <!-- buttonRef -->
</a>
</span>
After adding a tempSpan
:
<span> <!-- containerRef-->
<a></a> <!-- buttonRef -->
<span></span> <!-- tempSpan -->
</span>
With tempSpan.appendChild(buttonRef.current)
:
<span> <!-- containerRef-->
<span> <!-- tempSpan -->
<a></a> <!-- buttonRef -->
</span>
</span>
Therefore, when restoring the state on error or inside useEffect
, it should be:
containerRef.current.replaceChild(buttonRef.current, containerRef.current.lastChild);
So that it goes back to initial state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason we have this tempSpan
is because this library runs async rendering that dispatches outside of react lifecycles, therefore we want to make sure when we come back to react lifecycle, react should not see any DOM patch that we have done so that it can patch DOM incrementally. In order to do that we have to restore the DOM to the state that react generates. The primary goal of using an additional tempSpan
is allow us to easily check if we have patched the DOM outside of react or not, and acting accordingly.
Update to latest react version
Closed #40