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

refactor: update to latest react version #39

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

NdekoCode
Copy link

@NdekoCode NdekoCode commented Aug 26, 2024

Update to latest react version

Closed #40

index.d.ts Outdated Show resolved Hide resolved
@NdekoCode NdekoCode requested a review from ntkme August 26, 2024 18:04
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@NdekoCode NdekoCode requested a review from ntkme August 26, 2024 18:29
buttonRef.current &&
containerRef.current &&
containerRef.current.lastChild === tempSpan
) {
render(tempSpan.appendChild(buttonRef.current), (el) => {
Copy link
Contributor

@ntkme ntkme Aug 26, 2024

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.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript Compatibility Issues and React Version Concerns
2 participants