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

Using Highlighter and TextRange with React #484

Open
MimmyJau opened this issue May 25, 2023 · 0 comments
Open

Using Highlighter and TextRange with React #484

MimmyJau opened this issue May 25, 2023 · 0 comments

Comments

@MimmyJau
Copy link

Hi, apologies if this is a basic question. I've been banging my head against the wall on this and feel like I must be missing something straightforward.

I'm attempting to use Rangy and the Highlighter + TextRange modules in a React project that lets users serialize highlights and then later de-serialize them. It's the de-serialization part that is causing trouble.

Approaches for deserialization:

  1. Manipulate DOM directly: This is an anti-pattern in React, and I eventually came across some issues where React's virtualDOM and the browser's actual DOM got out of sync, leading to some React-specific bugs.
  2. Manipulate DOM object and pass as prop: The alternative is to have Rangy add the Highlights to a DOM object that's held as state and then pass it as an HTML string and via something like dangerouslySetInnerHTML. However, while this works with many of Rangy's functions, the TextRange library seems to require working with a DOM that's actually rendered in the window.
  3. Don't use TextRange: I considered using textContent instead, but one feature I want is the ability to start serialization within a specified node. This is a parameter offered in many of TextRange's functions, but not available in Highlighter.serialize().

What am I missing? Is my understanding of the library incorrect? Thanks in advance.

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

No branches or pull requests

1 participant