Skip to content

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

Open
gunjanjaswal wants to merge 2 commits into
facebook:mainfrom
gunjanjaswal:fix/12214-excerpt-multiline-jsx
Open

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

Conversation

@gunjanjaswal

Copy link
Copy Markdown

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.

@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 c533605
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a447f73b8b0ce0008cb5c26
😎 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

1 participant