Skip to content

fix(richtext): text reads the way it is written, in either document direction - #7723

Merged
cixzhang merged 20 commits into
meta:mainfrom
potatowagon:richtext-rtl-block-direction
Nov 17, 2026
Merged

cixzhang merged 20 commits into
meta:mainfrom
potatowagon:richtext-rtl-block-direction

Conversation

@potatowagon

@potatowagon potatowagon commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Scope

Packages: @astryxdesign/richtext, @astryxdesign/core.

Components: component:Markdown, firstStrongDirection.

component:Markdown does render differently, in one way: it shares the
classifier, so a line that opens with tatweel, the Arabic semicolon or
question mark, a Rumi digit, or a digit of any script whose digits are
Bidi_Class L — Devanagari, Bengali, Gujarati, Telugu, Tamil, Thai, Lao,
Myanmar, Khmer, Tibetan and 46 others — now takes a different direction, and
so does one opening with a Hanifi Rohingya,
Garay or Yezidi digit, the Phoenician word separator, Avestan punctuation, a
Garay hyphen or an Arabic mathematical operator — every character the sweep
against the browser found misread. Nothing else about its output changes. The
change to @astryxdesign/core is that correction alone: no API is added or
removed.

RichText keeps its own copy of the classifier in
packages/richtext/src/internal/firstStrongDirection.ts, because Core's
internal/* entry points are reserved for Core and Lab. Each copy carries a
SYNC comment naming the other, and each has the same test, so a correction
to either set is visible in both. Sharing one classifier across packages is
its own decision, not this one.

The bug

spec:AST-061 FR6 gives a prose block the direction of its own text on every
surface. Core Markdown already follows it. RichTextEditor and
RichTextView still take the provider's direction for every block, so a
Hebrew paragraph in an English document flushes left and its caret moves
opposite to the arrow key; an English paragraph, list item or table cell in a
Hebrew document does the mirror.

Repro: open RichTextEditor → Playground, paste
פסקה בעברית לבדיקת כיוון הטקסט., click into it and press Right.

The fix

BlockDirectionPlugin writes each prose container's own direction onto it, at
any depth, from RichText's own copy of firstStrongDirection. Containers take their
parent's direction instead and give up a dir that arrives with pasted HTML
or an older stored document.

const own = firstStrongDirection($proseText(node));
if (node.getDirection() !== own) {
  node.setDirection(own);
}

Why write it rather than derive it in CSS. Under dir="auto" a block of
English, a block of digits, an image-only block and an empty block are all
:dir(ltr), so a rule that catches the first catches the other three. An
earlier draft used a symmetric :dir() rule and broke the right-to-left
image-resize test. Writing the attribute is the only thing that can say "this
block has no direction of its own"; such a block is left alone and follows the
document, so an empty paragraph keeps its caret on a right-to-left document's
start edge.

Only text a reader reads decides it. A decorator shows no prose of its
own, and getTextContent returns its alternative text, so an English caption
would turn a Hebrew list item left-to-right. Core Markdown skips the same
nodes.

Containers. A list orders its markers and insets in its parent's
direction; a table reads its columns that way; a fenced code block frames its
lines that way and adds unicode-bidi: plaintext, so each line reads its own
way — a Hebrew comment right-to-left while const x = 1; keeps its semicolon
at the end. Core Markdown reaches the same rule a different way: it renders
fences through CodeBlock, which puts each line's code in its own dir="auto"
element (component:CodeBlock FR16). RichText has no per-line node to carry
one.

Where the two surfaces still differ, recorded as a gap in AST-061: the
text start of an item that reads against the list holding it, where the two
hold the themed inset in different places.

List geometry. The themed inset sits on each item's own start side, not
on the list. An outside marker is drawn beyond its item's own start edge,
which is the opposite edge from the list's when the two disagree, so an inset
held by the list reserved room on the side the marker is not on and let it
escape the field. Held by the item it is always on the marker's side and costs
the same measure either way, so a list whose items agree with it wraps where
core Markdown wraps. Measured at 390 px, English items three deep under a
Hebrew-first
wrapper go from 24 / 24 / 24 to 24 / 48 / 72; a uniform list in either
direction keeps the geometry it had, and nothing overflows.

Undo. Typing dirties a text node, not its container, so the write happens
in a TextNode transform that walks every prose ancestor — inside the
keystroke's own update, and so in its own history entry. An update listener
sweeps a whole-state replacement, which runs no transforms, tagged
history-merge so undo does not bounce off it.

The shared classifier

This also fixes two defects in packages/core/src/i18n/firstStrongDirection.ts,
which Markdown already ships:

before   ltr    "ـها ضمير متصل"   tatweel, Bidi_Class AL, Script=Common
before   rtl    "𐹠𐹡 Annual"       Rumi numerals, Bidi_Class AN
before   rtl    "०१ שלום"        Devanagari digits, Bidi_Class L

Three AL characters whose script is Common — the semicolon, the question
mark and tatweel — join the strong set (the letter mark was already there),
and the Rumi numerals join the weak one. The Indic and Ottoman Siyaq blocks
look like company for Rumi and are not: they are AL, so they stay strong. JavaScript exposes no
\p{Bidi_Class=…} escape, so the sets approximate it from script and category.
They name the characters this surface has needed where the two disagree; about
3,600 others still disagree, as before: some Arabic and NKo ON signs, ON
modifier letters, and L punctuation (firstStrongDirection.ts).
firstStrongDirection.test.ts covers the named ones.

Both copies of the classifier carry the fix, and both test files cover it.

manual test (by human)

BUG: cursor moving in the opposite direction of the arrow key for RTL in a LTR doc and LTR in a RTL doc

before:

Screen.Recording.2026-10-28.at.7.49.25.PM.mov

^ a RTL in a LTR document has the cursor moving in the opposite direction of the arrow key. eg. arrow right moves cursor left. Vice versa for a LTR in a RTL document

after:

Screen.Recording.2026-10-28.at.4.00.20.PM.mov

known issue due to an unrelated factor

after:
Screenshot 2026-10-28 at 3 42 30 PM

^ why in a RTL the LTR doc doesnt flush all the way right and theres a gap:

Prose is capped at 680px (PROSE_MEASURE, editorTheme.ts:34) per spec:AST-061 FR2–FR4, matching core Markdown's content width — long lines are hard to read. Tables and code blocks are exempt, which is why the table reaches the edge and the Hebrew paragraph stops 220px short.

// …prose capped at Markdown's default content width
// while code and tables span the editor.
const PROSE_MEASURE = '680px';

Tests

Core. firstStrongDirection.test.ts — ten cases over the classifier,
including leading combining marks, letter numbers, the three Arabic AL
marks and the three AN numeral blocks. The last two groups fail with this
change reverted.

RichText, jsdom. internal/BlockDirectionPlugin.test.tsx — ltr/rtl/auto on the
right containers in both surfaces, a rewrite when the view is handed a new
document, a stored <ul dir="rtl"> giving its direction up, a three-deep
list whose wrappers all carry a direction, and three that drive a real Lexical
editor and read the state of the update that is not tagged
history-merge — the one a caller's onChange sees — to prove the write
lands in the keystroke's own update, reaches a grandparent block, and
survives a paragraph being removed from a quote.

RichText, Chromium. BlockDirection.a11y.chromium.spec.ts is the undo
guard: - +Hello+Ctrl+Z and 123 +שלום+Ctrl+Z both walk back to an
empty document. MarkdownParitySandbox now states one rule for both
surfaces, and adds a nested list stepping in once per level whichever way its
items read, and a table cell read past a combining mark and a letter number,
each in both document directions.

Two existing tests move with the rule rather than against it. The parity
sweep reads only document blocks, since a toolbar dialog's heading is chrome
and follows the provider. The right-to-left resize test puts its image in a
right-to-left block it writes itself: this document's own last block is
English, so under FR6 it reads left-to-right and an image in it has its handle
on the right.

At 804d6ed: 1895 unit tests pass, eslint 0 errors, tsc --noEmit
clean on both packages, Prettier clean. The richtext Chromium suite is 108
passed, 1 failed
— a selected image resizes by its handle, which fails
the same way on pure main (expected > 585, received 584) and is not this
branch's.

The record

spec:AST-061 claims the six files that carry the rule — both copies of the
classifier, Markdown/blockDirection.ts, the plugin and its test, and the
RichText editor theme — through a path-applicability:v1 block. That record
change is approved for this head.
Its Current-state impact says what the plugin is for and why core's
Markdown/blockDirection.ts does not cover it: Markdown renders from an
abstract syntax tree and can resolve a block's direction as it renders, while
the RichText surfaces render from Lexical's stored editor state, so the
direction has to be written onto the node inside the keystroke's own update —
to sit in that keystroke's undo step, and to survive storing and reopening the
document. A render-time resolver can do neither.

A module record would be the narrower home, but every one in this repository
declares a parent_component that must resolve to an active component record,
and there is no component:RichTextEditor or component:RichTextView to
parent it to. Authoring those is maintainers' work, not an outside
contributor's, so the rule stays with the system spec that already decides it.

Writing rubric results

  • R1 state the system, not the project: the added text is present tense and
    describes what each surface does. No proposal, history or porting language.
  • R2 research in the record: none. The standards comparison and the
    code-point sweeps stay in this pull request's comments.
  • R3 evidence naming a change: none added; no pull request, issue or commit
    is cited.
  • R4 rejected alternatives: none added.
  • R5 pull request or issue references: none in the record.
  • R6 ruled open questions still listing options: none added. The two open
    decisions are stated in this description, not in the record.
  • R7 project status: none. The gap lines this edit leaves use the sanctioned
    FR5 gap: form and name an observable mismatch.

Maintainer additions (this head)

Carried for the maintainers on the contributor's branch, with main merged in. There are no changes to the component's code, styles or markup, and the AST-061 record reads as it did at the approved head.

  • First paint, real browser: BlockDirection.a11y.chromium.spec.ts gains "a seeded document paints every block on its own side on the first frame (rtl page)". The story's provider and the page around the editor read right to left. A frame callback installed before any page script records each block's computed direction on the first frame that holds them: the English paragraph is ltr and the digit-only paragraph is rtl. Moving the plugin's settle from a layout effect to an ordinary effect fails it (3 of 3 runs). The new MixedDirectionSeed story holds the seeded document.
  • A seeded mount is not an edit: BlockDirectionPlugin.test.tsx checks that RichTextEditor mounted with a seeded document fires no onChange. A second case mounts the plugin on a document the editor already shows, whose list item has no stored direction, and checks that the write fires no onChange either. Lexical already tags its first commit, and a transform registration's update, as a history merge, so removing the plugin's own tag alone is not observable here; the test pins the outcome.
  • Local gates: the RichText unit tests and the core i18n tests pass (970). The RichText and List-marker Chromium specs pass (135; 4 skipped, unchanged), run on a built Storybook in a Linux Chromium 149 headless shell. ESLint, TypeScript and check:knowledge are clean.

Respin

This branch was rebuilt on current main.

It had fallen 862 commits behind while the spec amendment was decided, and in
that time main gained the Markdown half of FR6 — the shared classifier,
Markdown/blockDirection.ts, and a parity fixture that describes Markdown
taking its own text's direction. Replaying the old sixteen commits through
that conflicted from the first one and produced intermediate states that did
not build, so the work was re-applied onto main instead: same behaviour,
with RichText keeping its own copy of the classifier, which Core's
internal-entry rule requires.

The review history above refers to those commits. Every finding from it is in
this one, and the two that were parked behind the spec decision — the
mixed-direction nesting step and the wrapper's stored direction — are fixed
here.

Commits

On current main, which is merged in. The first commit carries the behaviour;
the rest are the review rounds over it. git log --oneline upstream/main..HEAD
on the head gives the current list.

@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 17, 2026 8:47pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 20, 2026
@astracat-bot

astracat-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 17, 2026, 9:08 PM UTC

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 118a69b

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
richtext/RichTextView 285.2 kB (+1.4 kB) · 2.4 kB CSS (+95 B) 184 (+3) — · ✓ · —
richtext/RichTextEditor · Storybook 308.0 kB (+944 B) · 2.7 kB CSS (+87 B) 696 (+3) — · ✓ · ✓
lab/CommentThread 370.3 kB (+130 B) · 2.4 kB CSS (0) — — · — · —
20 more components
Component Size LoC Visual · A11y · RTL
lab/Comments 377.0 kB (+116 B) · 2.5 kB CSS (0) — — · — · —
Markdown 205.5 kB (+109 B) · 22.1 kB CSS (0) — — · — · —
ChatToolCalls 33.8 kB (+15 B) · 8.5 kB CSS (0) — — · — · —
Typeahead 89.2 kB (+15 B) · 13.5 kB CSS (0) — — · — · —
lab/DiffViewer 94.4 kB (+15 B) · 2.1 kB CSS (0) — — · — · —
ChatComposer 85.8 kB (+14 B) · 12.9 kB CSS (0) — — · — · —
ChatTokenizedText 7.6 kB (+14 B) · 4.0 kB CSS (0) — — · — · —
lab/TabBarMoreList 102.4 kB (+14 B) · 1.8 kB CSS (0) — — · — · —
Badge 4.4 kB (+13 B) · 4.0 kB CSS (0) — — · — · —
ChatComposerDrawer 18.2 kB (+13 B) · 4.7 kB CSS (0) — — · — · —
InputGroupText 6.9 kB (+13 B) · 3.9 kB CSS (0) — — · — · —
MultiSelector 103.2 kB (+13 B) · 17.8 kB CSS (0) — — · — · —
lab/CommentComposer 180.5 kB (+13 B) · 1.9 kB CSS (0) — — · — · —
ChatComposerInput 83.5 kB (+12 B) · 12.1 kB CSS (0) — — · — · —
ChatComposerTokenElement 83.5 kB (+12 B) · 12.1 kB CSS (0) — — · — · —
PowerSearch 310.3 kB (+11 B) · 25.6 kB CSS (0) — — · — · —
Token 29.7 kB (+10 B) · 4.9 kB CSS (0) — — · — · —
Tokenizer 105.9 kB (+9 B) · 20.4 kB CSS (0) — — · — · —
List 19.0 kB (0) · 790 B CSS (0) — ✓ · ✓ · —
ListItem 79.5 kB (0) · 12.1 kB CSS (0) — ✓ · ✓ · ✓

Package size:

  • @astryxdesign/core 7.66 MB packed (+1.9 kB); no new dependencies
  • @astryxdesign/richtext 261.4 kB packed (+13.2 kB) 🔴; no new dependencies

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for chasing down the inverted caret: it is real, and this change fixes it for top-level Hebrew paragraphs. Approval waits on a maintainer decision. spec:AST-061 FR6 currently says a surface does not choose a block's direction from its text, so a maintainer needs to either update FR6 to allow this exception (and say whether core Markdown follows it) or keep FR6 as written. Separately, these need fixing whichever way that goes:

  • A list whose first item is Hebrew now turns every item right-to-left in an English document, so Buy milk. renders as .Buy milk; keeping ul/ol on the surface direction avoids it.
  • A fenced code block whose first line is a Hebrew comment turns right-to-left, so const x = 1; renders as ;const x = 1 and the copy button covers the first line; keeping code on the surface direction avoids it.
  • The changeset says such a block reads right-to-left "wherever it sits", but a Hebrew item in a list that starts in English is unchanged, and the parity test should keep its nested-direction check for core Markdown.

[Automated review]

Comment thread packages/richtext/src/editorTheme.ts Resolved
@potatowagon potatowagon changed the title fix(richtext): a right-to-left block reads right-to-left in a left-to-right document fix(richtext): a block reads the way its own text reads, in either document Oct 20, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the careful write-up: the inverted caret is real on the base, and this head fixes it for top-level Hebrew paragraphs. Approval waits on a maintainer decision, because spec:AST-061 FR6 currently says a surface does not choose a block's direction from its text, so a maintainer needs to amend FR6 and its verification row (and say whether core Markdown follows) or keep it as written. Independently of that decision, these need fixing:

  • Undo gets stuck once a keystroke changes a block's own direction: typing - Hello and pressing Ctrl+Z stops at H instead of removing the list, because the direction sweep in BlockDirectionPlugin runs as its own history step.
  • A list whose first item is Hebrew, or a code block whose first line is a Hebrew comment, still turns right-to-left as a whole, so Buy milk. renders as .Buy milk and const x = 1; as ;const x = 1.
  • The Markdown half of the FR6 parity test should keep its nested tr, th, td, li, p check, since this change does not touch Markdown.

[Automated review]

@potatowagon
potatowagon marked this pull request as draft October 20, 2026 15:33
potatowagon added a commit to potatowagon/astryx that referenced this pull request Oct 20, 2026
… direction write out of history

Review feedback from astracat-bot on meta#7723.

A list and a fenced code block hold several lines under one element, so
one `dir` on the element imposes the first line's direction on all of
them: under a Hebrew first item `Buy milk.` rendered `.Buy milk`, and
under a Hebrew first comment `const x = 1;` rendered `;const x = 1`.
They leave `dir="auto"` now, which the theme styles as the document's
direction and under which the browser reads each line on its own.
ParagraphNode, HeadingNode and QuoteNode are read as one piece of prose
and keep their own direction.

The direction write also cost an undo step. Typing inside an existing
text node dirties the text node, not the block, so no element transform
ran and the update listener was doing the work -- in an `editor.update`
of its own, which became its own history entry. Undo restored the stale
direction, the listener swept again, and undo never got past it: `- ` +
`Hello` then Ctrl+Z left `H`. A TextNode transform now writes the
direction inside the update that changed the text, and the whole-state
sweep that RichTextView needs is tagged `history-merge`.

The Markdown half of the FR6 parity test keeps its nested
`tr, th, td, li, p` check: this change does not touch core Markdown.
@potatowagon

Copy link
Copy Markdown
Contributor Author

Thanks — all three are real, and all three are fixed in 0ddeb45. Taking them in turn.

Lists and fenced code blocks. You are right, and the fix is the one you suggested. ListNode and CodeNode are out of the set that carries its own direction, so they keep dir="auto" and the theme gives them the document's direction. The reasoning I have written into the plugin is that a list and a code block are several lines under one element, so a single dir on the element imposes the first line's direction on the rest — the same reason a table is out. ParagraphNode, HeadingNode and QuoteNode are read as one piece of prose and keep theirs.

Worth noting what the browser then does, because it is better than "no direction handling": under dir="auto" a <ul> gets unicode-bidi: isolate and a <pre> gets plaintext, so a Hebrew item still reorders correctly as a right-to-left run, a Hebrew comment line still reads right-to-left, and Buy milk. and const x = 1; are untouched. Measured in Chromium, with the items' visual character order read out of client rects rather than from the DOM.

Per-item direction inside a list is a real improvement and is reachable — the reconciler emits dir at any depth once __dir is set — but it is a bigger change than this fix, so I have noted it in the PR body as a follow-up rather than smuggling it in here.

Undo. Good catch, and your diagnosis was exactly right, including why: typing inside an existing text node dirties the text node and not the block, so no element transform ran for that keystroke and the update listener was doing the work — in an editor.update of its own, which became its own history entry.

Fixed the way you suggested: a TextNode transform walks up to the top-level block and writes the direction inside the update that changed the text, so it rides in that keystroke's own history entry. The update listener survives only for a whole-state replacement, which runs no transforms and is what RichTextView does on every value change, and it is now tagged history-merge.

Both of your repros are now regression tests in a new BlockDirection.a11y.chromium.spec.ts, in a real browser: - + Hello + Ctrl+Z and 123 + שלום + Ctrl+Z both walk back to an empty document. I checked they fail on the previous commit of this branch and pass on its head, so they are guarding the thing you found rather than just passing.

The parity test's nested check. Restored. The Markdown half keeps the base's tr, th, td, li, p check, since this change does not touch core Markdown. I also took the fixture suggestion, but through the markdown-serializers story rather than the shared parity fixture — a new a Hebrew-first list and code block keep the document direction (ltr|rtl) fills the textarea with a Hebrew-first list and a Hebrew-commented code block and asserts both stay dir="auto", compute to the document's direction, and leave Buy milk. reading Buy milk.. Adding those blocks to MARKDOWN_PARITY_BLOCKS instead would have moved a shared visual baseline for a rule that only needs two blocks to exercise, which seemed like the wrong trade; happy to move them into the fixture if you would rather have them there.

Changeset. Narrowed. "Wherever it sits" now says paragraph, heading or quote, and names what keeps the document's direction.

On the FR6 decision, which is yours and not mine: the PR body sets out why I think the editor should be narrower than FR6 reads today, and I have no attachment to winning it. If FR6 is meant to bind RichTextEditor as strictly as it binds the renderer, the minimum fix is still needed — the override has to neutralise dir="auto" rather than take half of it, or the caret keeps walking backwards through right-to-left text, which is the one part of this nobody is arguing for.

Suite after the changes: 94 chromium, 600 unit, no new typecheck errors, lint and repo checks clean.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the careful fixes: the undo regression and the Hebrew-first list and code block cases from the last round are resolved, and the caret now follows the arrow keys in a right-to-left paragraph. Approval waits on a maintainer, because spec:AST-061 FR6 currently says content blocks take the provider's direction and that a surface does not choose a block's direction from its text, so a maintainer needs to update FR6 and its verification row to allow own-text direction for paragraphs, headings and quotes (and say whether that covers RichTextEditor only, RichTextView too, or core Markdown as well) or keep FR6 as written. Independently of that decision, one fix is needed:

  • A list, code block or table-cell paragraph that arrives with an explicit dir (pasted HTML or a stored value) now keeps it, because block() still builds ul, ol and code on the new rule: a pasted <ul dir="rtl"> renders Buy milk. as .Buy milk in an English document, so keeping those classes on the unconditional document direction, as tablePart does, and clearing dir on nested paragraphs would fix it.

[Automated review]

Comment thread packages/richtext/src/editorTheme.ts Resolved
@potatowagon
potatowagon marked this pull request as draft October 22, 2026 07:41
@potatowagon potatowagon changed the title fix(richtext): a block reads the way its own text reads, in either document fix(richtext): text reads the way it is written, in either document direction Oct 22, 2026
potatowagon added a commit to potatowagon/astryx that referenced this pull request Oct 23, 2026
Review feedback from astracat-bot on meta#7723.

`ul`, `ol` and the table parts were built on the conditional rule, which
leaves an explicit `dir` alone. Nothing in the editor writes one onto a
container, but $setDirectionFromDOM does when HTML is pasted, and an
older stored document can carry one -- so a list pasted as
`<ul dir="rtl">` kept its markers and indent on the right in an English
document. Measured before this change: `ul=rtl li=ltr`.

Containers are built on the unconditional document direction now, as the
tables already were, and BlockDirectionPlugin clears a direction that
arrives on a list, a code block or a table part, so the stored state says
what the document shows. The item inside still carries its own, which is
what keeps `Buy milk.` reading `Buy milk.`.

A cell paragraph that arrives with an explicit `dir` keeps it, which the
review also raised: since the previous commit a cell's prose carries its
own direction by design, so an English paragraph in a right-to-left table
reading left-to-right is the intended behaviour, not a leftover.
@potatowagon

Copy link
Copy Markdown
Contributor Author

Thanks — the pasted-container case is real and is fixed in e0fcff5. A note on each half, since the two commits that landed after your review changed what was left.

The list. Confirmed and fixed as you suggested. ul, ol and the table parts are built on the unconditional document direction now, so a dir that arrives with a paste or an older stored document cannot turn a container around. BlockDirectionPlugin also clears a direction that arrives on a list, a code block or a table part, so the stored state says what the document shows rather than carrying a value the CSS is quietly ignoring.

The symptom had already narrowed by the time I measured it: since 7c17e20 each list item carries its own direction, so a stored <ul dir="rtl"> rendered ul=rtl li=ltr — the item text read Buy milk. correctly, but the list kept its markers and indent on the right in an English document. Wrong either way, and against this PR's own rule that a list orders in the document's direction. There is a regression test for it in blockDirection.test.tsx; it fails on the commit before the fix with expected 'rtl' to be null.

The cell paragraph. This one I have deliberately left, because it is now the intended behaviour rather than a leftover. Since 7c17e20 a cell's prose carries its own direction, so an English paragraph in a right-to-left table reading and editing left-to-right is the point: it was the reported bug. In a right-to-left document, before that commit, 18 of 18 list items and 8 of 8 cell paragraphs disagreed with their own text. The cell box still takes the document's direction, so columns keep their order.

Also fixed since your review, both reported against the published build:

  • A list item or table cell in a right-to-left document still flushed right with its arrow keys reversed, because the plugin only wrote to top-level blocks. A prose container now carries its own direction at any depth (7c17e20).
  • A fenced code block did too. I had left it alone claiming core Markdown rendered it the same way; measured, it does not — core Markdown's pre starts its code at the left edge in a right-to-left document while RichText's started at the right, so the two surfaces already disagreed and leaving it was not protecting parity. unicode-bidi: plaintext gives each preserved line its own bidi paragraph, so a code line reads const x = 1; with its semicolon at the end in either document and a Hebrew comment line reads right-to-left (fcf55a8). That is also a cleaner answer to the Hebrew-comment case from your first round than a single direction on the block could have been.

Suite: 96 chromium, 601 unit, no new typecheck errors, lint and repo checks clean. The FR6 scope question is still yours.

@potatowagon

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (was 502 commits behind), no content change: same six commits, now 73be2dd..0047093.

pr-a11y was failing for a branch-age reason rather than anything in the diff. The job selects which accessibility specs to run using current main's routing policy and then runs them against the PR head, and it selected packages/core/src/MultiSelector/MultiSelector.disabledFocus.a11y.chromium.spec.ts, added to main on 22 Oct in b2c4f18 — after this branch's base of 16 Oct. The file did not exist at the head, so Playwright reported "No tests found" and exited 1. The spec is present after the rebase.

One conflict, in RichTextView.tsx: main had added a codeLanguages prop to CodeBlockHeaderPlugin and CodeSyntaxPlugin on the lines where this branch adds <BlockDirectionPlugin />. Resolved by keeping both.

Re-run after the rebase: 603 unit tests pass, tsc --noEmit reports exactly main's own baseline with nothing in the files this PR touches, eslint src has 0 errors. The browser suite is left to CI — the machine I rebased on cannot launch Chromium.

I force-pushed with --force-with-lease, which rewrites a branch that has already been reviewed. The six commits are unchanged in content and message, so the per-commit review comments should still read against the same diffs, but apologies if it costs anyone a re-read.

potatowagon added a commit to potatowagon/astryx that referenced this pull request Oct 27, 2026
… direction write out of history

Review feedback from astracat-bot on meta#7723.

A list and a fenced code block hold several lines under one element, so
one `dir` on the element imposes the first line's direction on all of
them: under a Hebrew first item `Buy milk.` rendered `.Buy milk`, and
under a Hebrew first comment `const x = 1;` rendered `;const x = 1`.
They leave `dir="auto"` now, which the theme styles as the document's
direction and under which the browser reads each line on its own.
ParagraphNode, HeadingNode and QuoteNode are read as one piece of prose
and keep their own direction.

The direction write also cost an undo step. Typing inside an existing
text node dirties the text node, not the block, so no element transform
ran and the update listener was doing the work -- in an `editor.update`
of its own, which became its own history entry. Undo restored the stale
direction, the listener swept again, and undo never got past it: `- ` +
`Hello` then Ctrl+Z left `H`. A TextNode transform now writes the
direction inside the update that changed the text, and the whole-state
sweep that RichTextView needs is tagged `history-merge`.

The Markdown half of the FR6 parity test keeps its nested
`tr, th, td, li, p` check: this change does not touch core Markdown.
spec:AST-061 FR6 gives a prose block the direction of its own text on
every surface. Core Markdown already follows it. RichText still took the
provider's direction for every block, so a Hebrew paragraph in an English
document flushed left and its caret moved opposite to the arrow key, and
an English list item in a Hebrew document did the mirror.

BlockDirectionPlugin writes each prose container's own direction onto it,
at any depth, from the shared first-strong classifier. A container -- a
list, a table and its parts, a fenced code block -- takes its parent's
direction instead, and gives up a dir that arrives with pasted HTML or an
older stored document. A fenced code block adds unicode-bidi: plaintext,
so each line reads its own way: a Hebrew comment reads right-to-left
while const x = 1; keeps its semicolon at the end. That is the one place
the surfaces differ, and core Markdown wants the same treatment.

Only text a reader reads decides a direction. A decorator shows no prose
of its own and getTextContent gives its alternative text, so an English
caption would have turned a Hebrew item left-to-right; core Markdown
skips the same nodes.

Writing the direction, not deriving it in CSS, is what separates a block
with no direction of its own from one that is strongly left-to-right:
under dir=auto, digits, an image and an empty block all resolve
left-to-right exactly like English, and a CSS rule cannot tell them
apart. An empty paragraph keeps its caret on a right-to-left document's
start edge because the plugin writes nothing onto it.

A list reserves marker room on both inline sides. An outside marker is
drawn beyond its item's own start edge, so room on one side left the
marker of an item that reads against its list outside the field, and
flattened a nesting step to nothing where a wrapper read against the
items inside it.

The direction write rides in the keystroke's own update, through a
TextNode transform that walks every prose ancestor. An update listener
sweeps a whole-state replacement, which runs no transforms, and is tagged
history-merge so undo does not bounce off it.

The shared classifier gains the four Arabic marks whose script is Common
-- the semicolon, the letter mark, the question mark and tatweel, all
Bidi_Class AL -- and loses the Rumi, Indic Siyaq and Ottoman Siyaq
numerals, which are AN inside ranges the strong set covers. JavaScript
exposes no Bidi_Class escape, so the sets approximate it from script and
category and name the characters where the two disagree.

The parity spec now states one rule for both surfaces, and reads only
document blocks: a toolbar dialog's heading is chrome and follows the
provider. The right-to-left resize test puts its image in a right-to-left
block, since the document's own last block is English and reads that way.

1895 unit tests pass, eslint reports no errors, tsc is clean on both
packages, and the richtext Chromium suite is 108 passed. The one failure,
a selected image resizes by its handle, fails the same way on main.
CI caught a parity regression from the previous revision. Reserving
marker room on both inline sides of every list cost one inset of measure
on the end side at every level, so a long RichTextView item wrapped onto
a second line where core Markdown kept it on one, and
ListMarkers.a11y failed on line counts at 1440px and 390px.

The inset goes back on the item, where an earlier revision had it. An
outside marker is drawn beyond its item's own start edge, so an inset
held by the item is always on the side the marker uses, whichever way
that item reads, and it costs the same measure either way: a list whose
items agree with it wraps exactly where core Markdown wraps.

Measured in a built Storybook, this keeps what the both-sides inset was
for. A nested list whose wrapper agrees with the items inside it still
steps 24 / 48 / 72, because a wrapper takes its direction from the first
text under it and so normally agrees with its own first item. No marker
escapes the field at 390px in either direction.

One narrower case stays open: a sibling that disagrees with the nested
list holding it starts one inset short, because the wrapper spent its
inset on the other side. Only room on both sides of that wrapper can fix
it, and that is what cost the measure, so it needs a rule that fires
only for a wrapper that disagrees with its items -- a change that moves
core Markdown too, since its lists are inset the same way.

ListMarkers.a11y keeps its two right-to-left fixme guards, with the
reason they actually have now. Both surfaces give a block its own
direction, so the old reason is spent; they still differ because
Markdown pads the list on its start side while RichText insets each
item, which is one inset apart exactly where an item reads against its
list. One of the four guarded cases passes with the guard removed; three
do not.

1079 unit tests pass, ListMarkers is 17 passed and 4 skipped, and the
richtext Chromium suite is 109 passed with the image-resize failure that
reproduces on main.
Review findings on the green head.

The Siyaq numerals are not weak. I put the Indic and Ottoman Siyaq
blocks in the weak set beside Rumi on the strength of their names; they
are Bidi_Class AL, and only Rumi is AN. Checked against the browser's
own implementation of the algorithm, which is what dir=auto runs: a
Siyaq numeral resolves right-to-left where a Rumi numeral falls through
to the next strong character. Both blocks come back out, the test that
pinned the wrong answer is corrected, and so is the changeset line.
This was mine, and it shipped in the shared classifier core Markdown
already uses.

Lexical puts a nested list in an item of its own after the item it
hangs from. That holder was read as prose, so it took the direction of
the list inside it, which is whichever language the first nested item
happens to use. Two things followed: an item reading the other way lost
its nesting step, because the holder had spent its inset on the far
side, and a neutral item -- digits, an image -- followed that first
item rather than the document.

A holder is not a block a reader sees. It belongs to the item above it,
and FR5 anchors a nested list on its parent item's text start, so it
takes that item's direction. Measured at 390px, an English sibling
under a Hebrew-first nested list moves from 24 to 48px, a neutral item
from the Hebrew item's edge to the parent item's, and an agreeing
nested list still steps 24 / 48 / 72.

One wording note for the record, not a code change: FR6 says a block
with no strong character takes the provider's direction, and a neutral
item here takes its parent item's. The two agree unless the parent item
reads against the provider. Writing the provider's direction onto the
block instead would store a value its own text does not carry and
freeze it for a reader who opens the document the other way round, so
the inherited value is kept and the parity test says so.

FR6 verification, in both document directions: a nested list whose
items read both ways with a neutral one among them, and a fenced code
line's own direction with the caret walking it the way the arrow
points. A fence keeps its lines in one text run separated by newlines,
so the line geometry is read from character ranges rather than nodes.

The two jsdom tests that drove a holder directly described the old rule
and used a holder with no item above it, which no document produces.
They now use the shapes that do, and a new one pins what the ancestor
walk is for: a quote two levels above the text that changed is settled
in the keystroke's own update, where a transform on the nearest block
alone leaves it reading left-to-right.

885 unit tests pass, tsc and eslint are clean, and the richtext and List
Chromium suites are 130 passed with the image-resize failure that
reproduces on main. blockNesting.test.tsx fails on main too.
Three review fixes.

The comment at $ownDirection cited FR5 for the rule it follows, which
is a claim id in source and what the provenance baseline exists to
catch. Regenerating the baseline had added an entry for the new file,
which switches the rule off for it rather than satisfying it. The
sentence now states the rule in its own words, the generated entry is
gone, and the baseline is byte-identical to main again: this change
does not touch it.

A new export is a compatible capability, so it needs its own [feat]
entry rather than riding the [fix] one, which never named it. The
changeset says what firstStrongDirection answers and that both surfaces
now share it.
check:changesets requires a contributor handle on its own line, which
the new [feat] entry was missing.
astracat found Hanifi Rohingya digits read as strongly right-to-left.
Rather than add one block, I swept both supplementary ranges in
STRONG_RTL against the browser's own implementation of the algorithm,
code point by code point, asking dir=auto what it makes of each one
followed by a letter. That found eight disagreements, not one.

The ranges are drawn around whole planes, so besides those scripts'
letters they swallow their digits and punctuation: the Phoenician word
separator, Avestan punctuation, the Hanifi Rohingya, Garay and Yezidi
digits, a Garay mark, and the Arabic mathematical operators. The Rumi
range also ran one code point past the block's end, onto a code point
the browser reads as strong. All are Bidi_Class AN, EN, ET or ON, so
none of them decides a direction, and they join the set the scan passes
over. The set is no longer only numbers, so it is renamed.

Re-running the sweep over all 2,816 code points in the two ranges now
reports no disagreement with the browser. The test names each block
with the class that put it there.

Restores the table-cell test from the review of 4 November, which asked
for leading Hebrew marks, combining-only content and Roman numerals in
both document directions through import and the editing path. It was in
the pre-rebase branch and I did not carry it over in the respin.

1918 unit tests pass, and the richtext and List Chromium suites are 132
passed. The image-resize and deep-nesting failures reproduce on main.
The new changeset claimed firstStrongDirection follows Unicode rules P2
and P3. It approximates them, and astracat's example shows where the
approximation was wrong rather than merely incomplete: ०१ שלום answered
rtl where P2 gives ltr, because a Devanagari digit is Bidi_Class L and
the classifier read every digit as neutral.

Sweeping all 770 decimal digits in the first two planes against the
browser, with two probes per code point to tell strong L from strong R
from weak, found 320 of them misread across 32 scripts -- Devanagari,
Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam,
Sinhala, Thai, Lao and the rest. Their digits are L, so a line that
opens with them reads left to right.

Decimal digits join the strong left-to-right set, and the digits that
are not L are named in the weak set that is read before it: the
European and fullwidth ones are EN, the Arabic-Indic ones AN, and the
mathematical, segmented and Nag Mundari ones EN. NKo's and Adlam's stay
R through their own script escapes. Re-running the sweep reports no
disagreement on any of the 770.

The changeset now says the function approximates P2 and P3 from script
and category, and names what it does not do: isolates.

22,028 unit tests pass. Two failures, blockNesting and postinstall,
reproduce on main.
The [feat] entry still said firstStrongDirection reads a Bidi_Class L
digit as neutral. That was true when the sentence was written and the
commit after it made those digits strong, so the entry described the
behaviour it had just removed. The isolates clause stands.
Two wording notes from review, both non-blocking.

The JSDoc on the newly public firstStrongDirection still claimed to
follow rules P2 and P3. It approximates them from script and category,
and it does not skip isolated runs, which is what the changeset already
said; the two now agree.

The [fix] changeset named only the Arabic marks and the Rumi numerals.
Reading a Bidi_Class L digit as strong changes Markdown output as well:
a line opening with Devanagari digits before Hebrew now reads
left-to-right where it read right-to-left. The entry says so and names
the scripts.
The rebase onto main moved RichText's plugins into src/internal/, which
made BlockDirectionPlugin an internal module that RichTextEditor and
RichTextView import from outside its folder with no current record
naming it.

AST-061 already decides the rule the module implements, so it claims the
four files that carry it through a path-applicability block: the shared
classifier, core Markdown's resolver, the plugin and its test, and the
RichText editor theme.

Its Current-state impact now says what the plugin is for and why core's
Markdown/blockDirection.ts does not cover it. Markdown renders from a
syntax tree and can resolve a block's direction as it renders. The
RichText surfaces render from Lexical's stored editor state, so the
direction is written onto the node inside the update that changed the
text: that is what puts it in the keystroke's own undo step, and what
makes a reopened document read the way it was written. A render-time
resolver does neither.

A module record would be the narrower home, but each one here declares a
parent_component that must resolve to an active component record, and
neither RichTextEditor nor RichTextView has one.

The test file's header named its pre-rebase filename.
Cindy decided both open questions on the pull request.

firstStrongDirection stays internal. It is no longer exported from
@astryxdesign/core/i18n; RichText reaches it through a new internal
entry point, @astryxdesign/core/internal/first-strong-direction, beside
the other internal entries, so the two surfaces still share one
classifier and nothing outside Astryx gains API. The [feat] changeset
that announced the public export is gone with it.

no-core-internal-import reserved those subpaths for Core and Lab, so it
now covers RichText too, which is an Astryx package shipped from this
repository. This widens a shared rule, so it is called out for an owner
rather than buried.

A block with no strongly directional text takes the document's
direction, as FR6 says and as Markdown already resolves one, instead of
the direction of the list or item holding it. The nested list still
anchors on its parent item's line, which the holder rule already does.

The mechanism stores nothing: the plugin puts the document's direction
on the editor root as a custom property, and a block with no written
direction reads that property. A custom property arrives unchanged
through a container whose own direction differs, where inherit handed
the block that container's direction. Nothing about a block's own text
is written unless its text decided it, so reopening a document under
the other provider direction still reads correctly.

Lexical leaves a top-level block at dir=auto and writes no attribute
below it, so the rule covers both spellings. List items now take the
block class that carries it; they took only their own layout styles
before, which is why a nested item followed its container.

958 unit tests pass and the parity suite is 46 passed.
Cindy corrected her earlier instruction: Core's internal entry points
are reserved for Core and Lab by architecture:public-component-api, and
widening no-core-internal-import to RichText changes that rule, which is
a separate owner decision.

So RichText keeps its own copy of the classifier in
packages/richtext/src/internal, with the same tests, and both copies
carry a SYNC comment naming the other. The Core internal entry point and
both lint-file edits are reverted: packages/core/package.json,
eslint.config.js and the rule are byte-identical to main again, which
also clears the sync-exports check that was failing on the generated
exports map.

AST-061 said both surfaces read the direction with the classifier in
core's i18n entry point, which is no longer true for RichText, and its
path-applicability block did not list the new file. Both corrected.

Comment drift: the holder item takes its direction from the item it
hangs from, not from the text under it, and three Arabic AL characters
are written into the strong set, not four.

The changeset now names Badge, Token and InputGroupText, which read the
same strong set to decide whether their own text is right-to-left, so
the digit correction reaches them too.

1329 unit tests pass, tsc and eslint are clean on both packages, and
check:knowledge, check-changesets, sync-exports and the provenance
baseline all pass.
design:bidirectionality DR9 rules out script where CSS can express the
same thing, and an Effect was writing the document's direction onto the
editor root after render.

The surface root now sets a private custom property from a :dir() rule,
as CodeBlock's root does, and a block whose own text decided nothing
reads that property. A custom property still arrives unchanged through a
list or table that reads the other way, which is what the property is
for. The Effect, the useDirection() read, the root listener and the
exported DOCUMENT_DIRECTION_VAR name are all gone; the plugin registers
its transforms and nothing else.

main gained component:CodeBlock FR16 while this branch sat, and it puts
each fence line's code in its own dir=auto element. Core Markdown
therefore meets FR6's per-line rule, where the theme comment, the plugin
comment, a unit-test comment and the description all still said it
reorders a whole block. Each now says both surfaces reach the rule, by
different means.

The changeset said Badge, Token and InputGroupText follow a label that
opens with any of the listed characters. They read the strong set to ask
whether the label holds a right-to-left character anywhere, so only the
three Arabic marks change them, wherever those sit.

Description: the plugin uses RichText's own copy of the classifier, not
a shared one; the Markdown-visible change lists every character the
sweep found, not only the first few; the real-editor test removes a
paragraph from a quote; twelve commits; and the R7 line cites the gap
form this edit leaves rather than the line it removes.

Also the weak-set comment in both classifier copies, which said the set
holds the right-to-left scripts' characters while it also holds the
ASCII, fullwidth and mathematical digits.

968 unit tests pass and the parity suite is 46 passed with no Effect in
the plugin.
DOCUMENT_DIRECTION_VAR named --astryx-richtext-document-direction and
described an Effect writing it on the editor root. Both went when the
surface root started setting --_richtext-document-direction from a
:dir() rule, and nothing imported the constant afterwards.

Both classifier comments said the sets name the characters where script
and category disagree with Bidi_Class. They name the ones this surface
has needed; others still disagree, as they did before this change, so
the comments say that instead of claiming the sets are complete.
The sweep cleared an arriving dir from lists, tables and code blocks but
walked from the root's children, so the root itself was never visited.
Lexical writes a stored root direction onto the editable element and
every container under it inherits, so a value saved in a right-to-left
document laid its tables and code frames out that way in an English one,
with the copy button over the code, and kept the stale value when saved
again.

The root is a container: it carries no text of its own, so it gives the
direction up and the surface decides. It joins the swept set, and
$isSettled answers for it directly, since $wantedDirection already
returns null for anything that is not a prose block.

The container test's fixture already carried a root direction, so the
case was there and unasserted; it now checks the root as well as the
list. Both assertions compare against the stored rtl rather than null,
because Lexical spells "no direction of its own" differently on a node
it rendered than on one it did not, and the direction the containers
take is what the test is about.

The inset comment on ol repeated ul's seven lines; it points at ul now.

968 unit tests pass and the richtext Chromium suite is 116 passed, with
the image-resize failure that reproduces on main.
The plugin registered its transforms in an ordinary effect, which React
runs after the browser has painted, so the first frame showed a block in
the document's direction and the write moved it.

It registers in a layout effect now, which React runs after Lexical has
written the document into the DOM and before paint, and settles the
document already in the editor in that same frame: registering only arms
the transforms, and a document loaded with the editor has run none of
them.

This does not make the rule expressible in CSS, which is what DR9 asks
first. Under dir=auto the HTML Standard resolves a block with no
strongly directional character to ltr, not to the surrounding
direction, so no selector separates a block of English from a block of
digits: both are :dir(ltr). unicode-bidi: plaintext resolves the same
way, and lays a neutral line out left in a right-to-left page while
leaving the computed direction saying rtl, which is why the parity
tests pass over it. The one direction the platform cannot express is
therefore the only one still written from script, and it is now written
before anything is shown.

Also: the SYNC line named two files that do not mirror this plugin;
they mount it and set the custom property. And editorTheme.ts had a
stray blank line.

968 unit tests pass, the parity suite is 46 passed, tsc and eslint are
clean, and the provenance baseline is untouched.
@potatowagon

Copy link
Copy Markdown
Contributor Author

On the test-node failure — it is not this pull request's, and I can show
the arithmetic rather than assert it. scripts/vitest-node-legs.mjs plan:

clean upstream/main   1649 files   longest leg 1393 s   budget 1387 s   fits: FALSE
this branch, rebased  1650 files   longest leg 1394 s   budget 1387 s   fits: FALSE

main is 6 s over budget on its own, before this branch exists. The
branch adds one file and 1 s to the longest leg, so removing every line of
it would still leave the suite over. Both of its classifier test files sit
in NODE_TEST_EXCLUDE (packages/core/**, packages/richtext/**); running
either under --project node reports No test files found.

It reaches this pull request only because test-node runs here at all: the
other open pull requests are docsite- or spec-only, so the leg is skipped on
them, and the first change to touch package source pays for the suite being
over. That is a repository-wide gate, and the fix the error asks for —
"Speed up the slowest test files" — is in test files this branch does not
touch and should not be editing from an outside contribution.

The branch is rebased onto main as of this push and is zero commits
behind, so the plan above is current.

@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 65c4833

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes requested: the right-to-left behaviour and the record change hold up at this head, and the direction write now runs in a layout effect before the browser's first paint, which addresses the flash from the previous round, so what remains is two description fixes.

  • The description says the classifier's sets "now name the characters where the two disagree", but the code comment in firstStrongDirection.ts (and your own count of about 3,600) says others still disagree, so please reword it to match the comment.
  • The Respin and Commits sections say the branch is 15 commits on main, but this head is 16, so please correct or drop the number.

Approval also waits on the change request an engineering owner left on 4 November, which stays open until that owner reviews again or dismisses it. CI's heavy jobs did not run on this head because CI was full, and one non-blocking comment suggestion is inline.

Claims and files checked

Review mode: full; reason: author-not-engowner

Claims:

  • Changeset: RichText blocks take their own text's direction in either document: verified (Chromium suite, captured frames).
  • Changeset: the shared classifier reclassifies three Arabic marks, the Rumi numerals and digits whose bidi class is L, so a line opening with Devanagari digits before Hebrew now reads left-to-right in Markdown: verified (code-point sweep, unit tests).
  • Changeset: Badge, Token and InputGroupText now count the three Arabic marks anywhere in a label: verified (only those three characters change there).
  • Changeset: code lines read their own way, top-level containers keep the document's order, a nested list follows its holder, and the stored value drops an arriving direction: verified (theme, plugin, unit and Chromium tests).
  • Description: Markdown changes only for the listed characters, and no API is added or removed: verified (sweep; API surface comparison shows no rows).
  • Description: RichText keeps its own copy of the classifier with SYNC comments and the same tests: verified (identical tests, identical answers on every code point).
  • Description: on the base, RichText takes the provider's direction and the caret walks against the arrow key: verified (caret probe).
  • Description: the plugin writes direction at any depth, containers give up an arriving direction, and decorators are skipped as Markdown skips them: verified.
  • Description: the list inset sits on each item and uniform lists keep their geometry: verified (theme values, nested-list parity test).
  • Description: the write lands in the keystroke's own undo step: verified (unit and Chromium undo tests).
  • Description: the classifier's before rows: verified.
  • Description: the sets now name every character where script and category disagree with the bidi class: false.
  • Description: ten core test cases, and reverting the change fails the named groups: verified.
  • Description: the record change is approved for this head: verified.
  • Description: the branch is 15 commits on main: false (16).

Files:

  • .changeset/richtext-text-block-own-direction.md: clear
  • docs/specs/AST-061-document-surface-parity/spec.md: clear
  • packages/core/src/List/ListMarkers.a11y.chromium.spec.ts: clear
  • packages/core/src/i18n/firstStrongDirection.test.ts: clear
  • packages/core/src/i18n/firstStrongDirection.ts: clear
  • packages/richtext/src/RichTextEditor.tsx: clear
  • packages/richtext/src/RichTextView.tsx: clear
  • packages/richtext/src/__tests__/BlockDirection.a11y.chromium.spec.ts: clear
  • packages/richtext/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts: clear
  • packages/richtext/src/__tests__/Playground.a11y.chromium.spec.ts: clear
  • packages/richtext/src/editorTheme.ts: clear
  • packages/richtext/src/internal/BlockDirectionPlugin.test.tsx: clear
  • packages/richtext/src/internal/BlockDirectionPlugin.tsx: non-blocking (settle comment; holder lag)
  • packages/richtext/src/internal/firstStrongDirection.test.ts: clear
  • packages/richtext/src/internal/firstStrongDirection.ts: clear

Automated review (maintainer link)

Comment on lines +315 to +316
// Registering only arms the transforms; a document already in the
// editor has run none of them. Settle it now, in this same frame.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking: in Lexical 0.52, registerNodeTransform marks every existing node of that class dirty and queues a transform pass, so the loaded document would be transformed anyway, just in a later microtask and without the root. This discrete sweep is what makes it synchronous. Suggested:

// Registering queues a transform pass over the loaded nodes, but not the
// root and not synchronously. Settle the whole document now, in this commit.

@cixzhang

Copy link
Copy Markdown
Contributor

(Posted by Cindy's agent.) Thank you, the first-frame fix works. A real-browser screencast of a fully right-to-left page shows left-to-right blocks on the left from the first painted frame, and neutral blocks on the right from the first frame too. The code block header, tables and code lines also check out against CodeBlock and spec:AST-061 FR6. Three things to add before merge, from the records; none changes the design:

  1. A first-render real-browser test. In a right-to-left page (provider and DOM both dir="rtl"), render an English block and a digit-only block, and assert their computed direction on the first painted frame: ltr for the English block, rtl for the digit-only block. It pins the design:bidirectionality DR9 fix so it can't regress.
  2. A test that opening a document reports no change. Mount the editor with a seed value and assert onChange doesn't fire. The mount-time update writes stored direction on strong blocks, so this guards against a caller seeing a change nobody made.
  3. Record the server-render gap in spec:AST-061 FR6's verification row. A layout effect doesn't run on the server, so a stated gap keeps the record honest, for example: "server-rendered documents whose strong blocks have no stored direction take the provider's side until hydration". Documents edited under this plugin already carry their strong blocks' direction, so this only affects older or imported documents. We'll track the fix separately.

CodeBunny's two description fixes (the classifier sentence and the commit count) still apply.

@humbertovirtudes humbertovirtudes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at 65c483334eb51ecbde58f983f40268263733a194 for the Table-direction change and its direct dependencies. This supersedes the 4 November change request: the four Hebrew-mark and Roman-numeral failures are resolved, with the no-strong fallback preserved.

Validation at this unchanged head: 32 committed unit tests and 8 Chromium tests passed, including table direction in both document directions and undo. Removing the combining-mark guard or Roman-numeral handling reproduces the respective failures. A review-only seed-mount probe also passed all 3 cases without firing onChange.

Non-blocking follow-ups, pls address:

  1. Add a first-painted-frame browser regression test in an RTL page for English and digit-only blocks.
  2. Commit the seed-mount test asserting that opening a document does not fire onChange.
  3. Record the server-render/hydration limitation in AST-061 FR6 verification.
  4. Correct the description: the classifier is an approximation, not an exhaustive Bidi_Class implementation; update the commit count to 16 or remove it.

These items do not block this code approval. Other review gates and CI remain independent; this is not a claim that all CI checks passed.

(Posted by an agent with Humberto’s explicit approval.)

cixzhang and others added 3 commits November 17, 2026 09:36
… from a seeded mount

A real-browser case records each seeded block's computed direction on the
first frame that holds it, in a right-to-left page: an English paragraph
reads ltr and a digit-only paragraph rtl. Unit cases check that mounting
with a seeded document, or mounting the plugin on a document already shown,
fires no onChange. The AST-061 FR6 verification row names the gap left for
server-rendered documents without stored directions.

Co-authored-by: potatowagon <[email protected]>
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 8e34922

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes requested: the right-to-left behaviour, the first-frame fix and the record change hold up at this head, and the three additions an engineering owner asked for are in, but one new record line is wrong.

  • The line added to the end of spec:AST-061 FR6's verification row says server-rendered documents whose strong blocks have no stored direction take the provider's side until hydration, but neither RichTextEditor nor RichTextView renders any block on the server (both render an empty editable, and the client settles each block's direction before its first paint), so please drop that sentence or say what holds, and drop the description's matching "remaining gap" and "follow-up fix" lines.

Both earlier description fixes are in, and the 4 November change request is settled by that owner's later approval. The record edit will need an engineering owner's /approve-spec again at the new head. CI's heavy jobs did not run on this head because CI was full; Lint passed. The record line and one non-blocking suggestion are commented inline.

Claims and files checked

Review mode: full; reason: author-not-engowner

Claims:

  • Changeset: RichText blocks take their own text's direction at any depth, in either document: verified (Chromium suite, captured frames).
  • Changeset: code lines read their own way; top-level containers keep the document's order; a nested list follows its holder; the stored value drops an arriving direction: verified (theme, plugin, unit and Chromium tests).
  • Changeset: the shared classifier reclassifies three Arabic marks, the Rumi numerals and digits whose bidi class is L, so a line opening with Devanagari digits before Hebrew reads left-to-right in Markdown: verified (classifier tests, code-point sweep).
  • Changeset: Badge, Token and InputGroupText count the three Arabic marks anywhere in a label: verified.
  • Description: Markdown changes only through the shared classifier, and no API is added or removed: verified (API surface comparison shows no rows).
  • Description: RichText keeps its own classifier copy with sync comments and the same tests: verified (identical answers on every code point).
  • Description: on the base, RichText takes the provider's direction and the caret walks against the arrow key: verified.
  • Description: the plugin writes direction at any depth, containers give up an arriving direction, and decorators are skipped: verified.
  • Description: the list inset sits on each item and uniform lists keep their geometry: verified (theme values, nested-list test); the three-deep 390 px numbers were not re-measured.
  • Description: the write lands in the keystroke's own undo step: verified (unit and Chromium undo tests).
  • Description: the classifier's sets name the characters this surface needed, and about 3,600 others still disagree: verified (about 3,540 under the available Unicode data).
  • Description: ten core test cases and the listed RichText unit and Chromium tests: verified.
  • Description: the record change is approved for this head: verified.
  • Description: no RichTextEditor or RichTextView component record exists to parent a module record: verified.
  • Description: this head changes no component code, styles or markup: verified.
  • Description: the first-frame test passes and fails with an ordinary effect: verified (5 of 5 each way).
  • Description: a seeded mount fires no onChange, and Lexical already tags those updates as history merges: verified.
  • Description: the record names a remaining server-render gap and a follow-up is queued: false (no block is server-rendered).
  • Description: local gates (970 unit tests; 135 Chromium passed, 4 skipped; lint, types and records clean): verified.

Files:

  • .changeset/richtext-text-block-own-direction.md: clear
  • apps/storybook/stories/RichTextEditor.stories.tsx: clear
  • docs/specs/AST-061-document-surface-parity/spec.md: blocking (server-render gap line)
  • packages/core/src/List/ListMarkers.a11y.chromium.spec.ts: clear
  • packages/core/src/i18n/firstStrongDirection.test.ts: clear
  • packages/core/src/i18n/firstStrongDirection.ts: clear
  • packages/richtext/src/RichTextEditor.tsx: clear
  • packages/richtext/src/RichTextView.tsx: clear
  • packages/richtext/src/__tests__/BlockDirection.a11y.chromium.spec.ts: non-blocking (header names the wrong story)
  • packages/richtext/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts: clear
  • packages/richtext/src/__tests__/Playground.a11y.chromium.spec.ts: clear
  • packages/richtext/src/editorTheme.ts: clear
  • packages/richtext/src/internal/BlockDirectionPlugin.test.tsx: clear
  • packages/richtext/src/internal/BlockDirectionPlugin.tsx: non-blocking (settle comment; holder lag)
  • packages/richtext/src/internal/firstStrongDirection.test.ts: clear
  • packages/richtext/src/internal/firstStrongDirection.ts: clear

Automated review (maintainer link)


/**
* @file BlockDirection.a11y.chromium.spec.ts
* @input The RichTextEditor "Default" story in a built Storybook.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking: the first-frame test below reads the MixedDirectionSeed story, not "Default". Suggested: @input The RichTextEditor "Default" and "MixedDirectionSeed" stories in a built Storybook.

Neither RichTextEditor nor RichTextView renders a block on the server: both
render an empty editable, and the client settles each block's direction
before the first paint. The gap line described a state that does not occur.

Co-authored-by: potatowagon <[email protected]>
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 118a69b

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved pending CI: CI has not finished on this head yet, and the merge guard waits for its required checks to pass.

RichTextEditor and RichTextView now give each paragraph, heading, quote and list item the direction of its own text in either document, as spec:AST-061 FR6 requires, and the record sentence about server-rendered documents that held the previous head is gone. Three non-blocking notes stay open in their inline threads: the settle comment in BlockDirectionPlugin.tsx, the holder item's one-edit lag, and the spec header that names only the Default story.

Claims and files checked

Review mode: full; reason: author-not-engowner

Claims:

  • Changeset: RichText paragraphs, headings, quotes and list items take their own text's direction at any depth, in either document: verified (Chromium suite, captured frames).
  • Changeset: each code line reads its own way; top-level lists, tables and code blocks keep the document's order and a nested list follows its holder; the stored value drops an arriving direction: verified (theme, plugin, unit and Chromium tests).
  • Changeset: the shared classifier reclassifies three Arabic marks, the Rumi numerals and digits whose bidi class is L, so a line opening with Devanagari digits before Hebrew now reads left-to-right in Markdown: verified (classifier tests, red-first run, code-point sweep).
  • Changeset: Badge, Token and InputGroupText count the three Arabic marks anywhere in a label: verified.
  • Description: Markdown changes only through the shared classifier, for the characters listed, and no API is added or removed: verified (API surface comparison shows no rows).
  • Description: RichText keeps its own classifier copy with sync comments and the same tests: verified (identical answers on every code point).
  • Description: on the base, RichText takes the provider's direction and the caret walks against the arrow key: verified (caret probe).
  • Description: the plugin writes direction at any depth, containers give up an arriving direction, and decorators are skipped as Markdown skips them: verified.
  • Description: the list inset sits on each item, uniform lists keep their geometry and nothing overflows: verified at 390 px; the three-deep before and after numbers were not re-measured.
  • Description: the write lands in the keystroke's own undo step: verified (unit and Chromium undo tests).
  • Description: the classifier's sets name the characters this surface needed, and about 3,600 others still disagree: verified (about 3,540 under the available Unicode data).
  • Description: ten core test cases, and the Arabic-mark and numeral groups fail with the change reverted: verified.
  • Description: the listed RichText unit and Chromium tests, and the two tests that move with the rule: verified.
  • Description: the record claims six files and its change is approved for this head: verified.
  • Description: no RichTextEditor or RichTextView component record exists to parent a module record: verified.
  • Description: this head changes no component code, styles or markup, and the record reads as it did at the earlier approved head: verified.
  • Description: the first-frame test passes and fails with an ordinary effect: verified (3 of 3 each way).
  • Description: a seeded mount fires no onChange, and Lexical already tags those updates as history merges: verified.
  • Description: local gates (970 unit tests; 135 Chromium passed, 4 skipped; lint, types and records clean): verified.

Files:

  • .changeset/richtext-text-block-own-direction.md: clear
  • apps/storybook/stories/RichTextEditor.stories.tsx: clear
  • docs/specs/AST-061-document-surface-parity/spec.md: clear
  • packages/core/src/List/ListMarkers.a11y.chromium.spec.ts: clear
  • packages/core/src/i18n/firstStrongDirection.test.ts: clear
  • packages/core/src/i18n/firstStrongDirection.ts: clear
  • packages/richtext/src/RichTextEditor.tsx: clear
  • packages/richtext/src/RichTextView.tsx: clear
  • packages/richtext/src/__tests__/BlockDirection.a11y.chromium.spec.ts: non-blocking (header names only the Default story)
  • packages/richtext/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts: clear
  • packages/richtext/src/__tests__/Playground.a11y.chromium.spec.ts: clear
  • packages/richtext/src/editorTheme.ts: clear
  • packages/richtext/src/internal/BlockDirectionPlugin.test.tsx: clear
  • packages/richtext/src/internal/BlockDirectionPlugin.tsx: non-blocking (settle comment; holder lag)
  • packages/richtext/src/internal/firstStrongDirection.test.ts: clear
  • packages/richtext/src/internal/firstStrongDirection.ts: clear

Automated review (maintainer link)

This branch was successfully deployed

1 active deployment
Preview — 118a69bf Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants