Skip to content

Fix nested <details> tag#403

Merged
haydenbleasel merged 2 commits intovercel:mainfrom
timneutkens:fix/nested-details
Feb 18, 2026
Merged

Fix nested <details> tag#403
haydenbleasel merged 2 commits intovercel:mainfrom
timneutkens:fix/nested-details

Conversation

@timneutkens
Copy link
Member

Description

Fix nested HTML block parsing in parseMarkdownIntoBlocks where nested elements of the same type (e.g. <details> inside <details>) would prematurely close the outer block, causing inner content to leak out as separate top-level blocks.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Related Issues

Changes Made

  • Fixed parseMarkdownIntoBlocks in lib/parse-blocks.tsx to count both opening and closing tags of the tracked type when merging tokens inside an HTML block, instead of only checking for the first closing tag
  • Added nested-details-tables.test.tsx with 5 focused tests covering the nested HTML block parsing bug

Testing

  • All existing tests pass
  • Added new tests for the changes
  • Manually tested the changes

Test Coverage

  • parseMarkdownIntoBlocks produces balanced open/close counts for 2-deep and 3-deep nesting
  • Rendered DOM correctly nests inner <details> inside outer <details>
  • Sibling content (headings, tables) after an inner </details> stays inside the outer <details>
  • Only one top-level <details> is produced for a fully nested structure

Screenshots/Demos

Using the Next.js stats action markdown:

Before

CleanShot 2026-02-18 at 12 11 42@2x

After

CleanShot 2026-02-18 at 12 15 02@2x

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have created a changeset (pnpm changeset)

Changeset

  • I have created a changeset for these changes

Additional Notes

Root cause: When merging tokens inside an HTML block, the code only checked for closing tags but never tracked new opening tags of the same type. A single nested </details> would pop the only entry on the HTML tracking stack, so the parser treated the outer block as closed and everything after became separate blocks.

@vercel
Copy link
Contributor

vercel bot commented Feb 18, 2026

@timneutkens is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

When the initial HTML block token contains multiple opening tags of the same type, only 1 entry is pushed to htmlStack, causing the first closing tag to prematurely terminate the HTML block merge.

Fix on Vercel

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@haydenbleasel
Copy link
Contributor

awesome, plays nicely with our recent similar fix 🚢

@haydenbleasel haydenbleasel merged commit 6e91867 into vercel:main Feb 18, 2026
2 of 5 checks passed
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.

2 participants