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

fix(forums): normalize newlines from synthetic events #3083

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wescopeland
Copy link
Member

@wescopeland wescopeland commented Jan 19, 2025

Resolves #3074 (comment).

Also, adds margin bottom to code tags (we should probably also apply the same margin bottom to quote tags).

Root Cause
React uses its own synthetic event system to maximize browser compatibility. For example, when a component has onClick={(event) => {...}}, this is not a native onclick="..." event. It's running through React's synthetic event system that emulates native events.

I've worked with React for a number of years and haven't hit a bug caused by synthetic events until now.

In our case, newlines were being sent to the preview component as escaped sequences (↵\n) after making any edit (ie: when initiating a synthetic event), but are served as actual newlines (\n) on load. I was able to observe this after putting a ton of logging in all the BBCode processors.

This fix normalizes all line endings to actual newlines (\n) during the preprocessing stage, ensuring consistent handling of whitespace regardless of how the newlines are represented in the input.

@wescopeland wescopeland requested a review from Jamiras January 19, 2025 20:08
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.

1 participant