Skip to content

fix: table section tags should implicitly close other table sections#2390

Open
vimzh wants to merge 3 commits intofb55:masterfrom
vimzh:fix/table-section-implicit-close
Open

fix: table section tags should implicitly close other table sections#2390
vimzh wants to merge 3 commits intofb55:masterfrom
vimzh:fix/table-section-implicit-close

Conversation

@vimzh
Copy link
Contributor

@vimzh vimzh commented Mar 22, 2026

Opening a <thead>, <tbody>, or <tfoot> should auto-close any currently open table section. This wasn't working for two reasons:

  1. <tfoot> was missing from tableSectionTags, so <tbody> after <tfoot> (or <tfoot> after <tfoot>) would nest instead of being siblings.
  2. <thead> had no entry in the openImpliesClose map at all, so <thead> after <tbody> would also nest incorrectly.

On top of that, the set also needed tr, td, and th because those elements sit above the section tag on the stack. The openImpliesClose mechanism only peels from the top, so it needs to be able to close through the row and cell elements to reach the section tag underneath.

For <table><tfoot><tr><td>F<tbody><tr><td>B</table>:

  • Before: <tbody> nested inside <tfoot> > <tr> > <td>
  • After: <tfoot> and <tbody> are siblings under <table>, matching browser/spec behavior

Verified against parse5 (spec-compliant reference parser) for all combinations of section tag ordering.

Ref: https://html.spec.whatwg.org/multipage/syntax.html#optional-tags

Opening a <thead>, <tbody>, or <tfoot> should auto-close any currently
open table section, including the row and cell elements on top of it.
Previously <tfoot> was missing from the close set, and <thead> had no
entry at all, so a <tbody> after <tfoot> (or <thead> after <tbody>)
would nest incorrectly instead of being siblings under <table>.

Expanded tableSectionTags to include tr, td, and th so the top-of-stack
close loop can peel off row/cell elements to reach the section beneath.

Ref: https://html.spec.whatwg.org/multipage/syntax.html#optional-tags
@fb55
Copy link
Owner

fb55 commented Mar 24, 2026

Thanks @vimzh!

@fb55 fb55 enabled auto-merge (squash) March 24, 2026 00:20
The `: [string]` annotations are incompatible with vitest's `any[][]`
typing for mock.calls, causing the TypeScript lint check to fail.
auto-merge was automatically disabled March 24, 2026 19:49

Head branch was pushed to by a user without write access

@vimzh
Copy link
Contributor Author

vimzh commented Mar 24, 2026

Hi! I pushed a fix for the TypeScript lint failure the : [string] tuple annotations on the mock.calls.findIndex destructuring were incompatible with vitest's any[][] typing. All checks should be green now. It looks like I accidentally pushed the code and it disabled auto-merge, really sorry about this I'm new to open source hope you understand, thanks.

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