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

Addition of x characters causes final x characters in <p> tag to be removed #66

Open
simonhrogers opened this issue May 23, 2024 · 4 comments

Comments

@simonhrogers
Copy link

Hello!

I adore this package it is invaluable, thank you so much for your work.

I’ve got the following replacement in a project:

smartquotes.replacements.push([/([0-9])–([0-9])/g, '$1\u200a–\u200a$2'])

and it is causing the following string to be editing from this:

A solo exhibition by Ndaye Kouagou opening on 21 September 2023 at 6–8 pm.

to this:

A solo exhibition by Ndaye Kouagou opening on 21 September 2023 at 6 – 8 p

As you can see, the hair spaces are correctly inserted, but the final two characters of the p tag are inexplicably removed.

This happens whether I paste the hair space character or use the regex unicode. It happens with regular spaces too; the problem seems to be unique to the en-dash character. It happens at the end of the P tag, whether or not there are subsequent P tags.

@simonhrogers
Copy link
Author

Whoops! Don’t think this repo is active but regardless for other people using in current projects: this seems to be a hydration error when used in an SSR context; in Vue 3’s case it was easily solved by wrapping in a setTimeout, as you might with Next/React too.

@simonhrogers simonhrogers changed the title Addition of half-spaces around en-dash is causing final two characters of edited <p> tag to be removed Addition of x characters causes final x characters in <p> tag to be removed May 30, 2024
@simonhrogers
Copy link
Author

hmm this doesn’t seem to be a hydration issue as I first thought... I’ve edited the title to describe it more broadly as it does appear to be any instance of the following: addition of x characters causes final x characters in

tag to be removed.

@simonhrogers simonhrogers reopened this May 30, 2024
@kellym
Copy link
Owner

kellym commented May 30, 2024

Thanks for filing a ticket for this issue. I'll take a look into it. I wonder if you or I can create a test to recreate the issue.

@kellym
Copy link
Owner

kellym commented May 30, 2024

I see what's going on, but I don't have a fix for it yet. Essentially, we concatenate the values of all the text nodes together, perform the regex on it, and then go back through all the text nodes to replace the old text with the new text. We keep track of the current index on the string so the right content goes back into the right text nodes. I have an idea of how to solve this, though.

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

2 participants