Repository navigation
[lexical-table] Bug Fix: toggleHeaderStyle stays inside TableCellHeaderStates - #9038
Merged
Merged
Conversation
…erStates
## Description
`TableCellNode.toggleHeaderStyle` tests its argument bitwise and then mutates
arithmetically:
```ts
if ((self.__headerState & headerStateToToggle) === headerStateToToggle) {
self.__headerState -= headerStateToToggle;
} else {
self.__headerState += headerStateToToggle;
}
```
The two agree only while the argument is a single bit. The parameter is typed
`TableCellHeaderState`, which includes `BOTH` (`3`), and `BOTH` is a
first-class member of the enum everywhere else in the same class —
`setHeaderStyles(headerState, mask)` masks with it, `hasHeaderState(BOTH)`
tests it, `getHeaderState` in `LexicalTableUtils` compares against it.
Passing it here overflows: a cell with `ROW` (`1`) that is toggled with `BOTH`
(`3`) ends at `__headerState === 4`, which is not `NO_STATUS`, `ROW`, `COLUMN`
or `BOTH`. `hasHeaderState(ROW)` and `hasHeaderState(COLUMN)` both go false
while `hasHeader()` stays true, so the cell renders as a `<th>` that belongs to
neither a header row nor a header column, and `4` is what `exportJSON` writes
out.
This keeps the existing branch — "does it already have all of these bits" —
and makes the mutation bitwise to match: clear those bits, or set them.
Single-bit arguments resolve to exactly the same values as before, which the
second test pins.
## Test plan
`npx vitest run packages/lexical-table/src/__tests__/unit/ToggleHeaderStyle.test.ts`
### Before
```
❯ |unit| packages/lexical-table/src/__tests__/unit/ToggleHeaderStyle.test.ts (2 tests | 1 failed) 12ms
× stays inside the enum when toggling BOTH 9ms
FAIL ... > TableCellNode.toggleHeaderStyle > stays inside the enum when toggling BOTH
AssertionError: expected 4 to be 3 // Object.is equality
- Expected
+ Received
- 3
+ 4
```
### After
```
Test Files 1 passed (1)
Tests 2 passed (2)
```
`npx vitest run packages/lexical-table` is green (12 files, 159 tests).
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 06:01
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
|
Confirmed the bug on |
etrepum
approved these changes
Aug 9, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
TableCellNode.toggleHeaderStyletests its argument bitwise and then mutatesarithmetically:
The two agree only while the argument is a single bit. The parameter is typed
TableCellHeaderState, which includesBOTH(3), andBOTHis afirst-class member of the enum everywhere else in the same class —
setHeaderStyles(headerState, mask)masks with it,hasHeaderState(BOTH)tests it,
getHeaderStateinLexicalTableUtilscompares against it.Passing it here overflows: a cell with
ROW(1) that is toggled withBOTH(
3) ends at__headerState === 4, which is notNO_STATUS,ROW,COLUMNor
BOTH.hasHeaderState(ROW)andhasHeaderState(COLUMN)both go falsewhile
hasHeader()stays true, so the cell renders as a<th>that belongs toneither a header row nor a header column, and
4is whatexportJSONwritesout.
This keeps the existing branch — "does it already have all of these bits" —
and makes the mutation bitwise to match: clear those bits, or set them.
Single-bit arguments resolve to exactly the same values as before, which the
second test pins.
Test plan
npx vitest run packages/lexical-table/src/__tests__/unit/ToggleHeaderStyle.test.tsBefore
After
npx vitest run packages/lexical-tableis green (12 files, 159 tests).