Skip to content

fix(utils): stop createExcerpt leaking a multi-line JSX element into the description#12215

Merged
slorber merged 3 commits into
facebook:mainfrom
gunjanjaswal:fix/12214-excerpt-multiline-jsx
Jul 3, 2026
Merged

fix(utils): stop createExcerpt leaking a multi-line JSX element into the description#12215
slorber merged 3 commits into
facebook:mainfrom
gunjanjaswal:fix/12214-excerpt-multiline-jsx

Conversation

@gunjanjaswal

@gunjanjaswal gunjanjaswal commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Motivation

Fixes #12214.

createExcerpt builds the auto description / og:description by scanning a doc line by line. It strips HTML/JSX with /<[^>]*>/g, which only matches a tag that opens and closes on the same line. When the first content node is a multi-line JSX/MDX element, only its first line is seen (e.g. <MyComponent), the regex finds no >, nothing is stripped, and that partial tag becomes the page description — e.g. <meta name="description" content="<MyComponent">.

This adds an inHTML state next to the existing inImport / inCode handling: when a line opens a tag with no > on the same line, skip lines until it closes. Single-line and self-closing tags are unchanged (the existing regex still handles them). The guard only triggers when a line starts (after whitespace) with <Tag and has no >, so it doesn't touch prose or current behavior.

Test Plan

Added creates excerpt after a multi-line JSX element in markdownUtils.test.ts. It fails before the change (excerpt is <MyComponent) and passes after. Runs with the existing docusaurus-utils unit tests.

AI assistance

This PR was written with AI assistance (Claude). The change is small and scoped to the reported bug; I understand and take responsibility for every line.

@meta-cla

meta-cla Bot commented Jul 1, 2026

Copy link
Copy Markdown

Hi @gunjanjaswal!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify

netlify Bot commented Jul 1, 2026

Copy link
Copy Markdown

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit fb8069e
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a47c0f8b7982800084cfa49
😎 Deploy Preview https://deploy-preview-12215--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@meta-cla

meta-cla Bot commented Jul 1, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Jul 1, 2026

@slorber slorber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Jul 3, 2026
@slorber slorber merged commit ca372bd into facebook:main Jul 3, 2026
36 of 37 checks passed
@gunjanjaswal gunjanjaswal deleted the fix/12214-excerpt-multiline-jsx branch July 3, 2026 14:37
@gunjanjaswal

Copy link
Copy Markdown
Contributor Author

Thanks for the review and merge, @slorber!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-generated description/og:description leaks the first line of a multi-line JSX element

2 participants