← Back to Pull requests

[lexical-selection] Bug Fix: Preserve mixed-block content when wrapping selections #9668

Open
unknown opened this pull request with 373 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 31, 2026 08:49 UTC
Author

Description

When a block holds text directly next to nested blocks, $wrapNodes can assign overlapping wrapping units. Moving a nested unit before its containing block can reorder text or leave the insertion anchor inside a new wrapper, producing a parent cycle.

Resolve each unit to the outermost block whose children will move, cache those ancestor lookups, and choose the insertion anchor from the resolved unit. Covered empty blocks stay in the moved subtree. An uncovered empty first block keeps its own insertion anchor so preceding siblings stay in place. The existing handling of declared block containers and inline runs is retained.

Addresses issue #9665

Changeset

.changeset/tidy-box-wrap.md adds a patch entry for @lexical/selection, with verification steps.

Test plan

Before

The new regression tests against main 21bcf62:

pnpm exec vitest run --project unit packages/lexical-selection/src/__tests__/unit/WrapNodesBlockLeaf.test.ts --maxWorkers=2
Tests 6 failed | 7 passed (13)

Both directions of the cycle case fail with getParent called more than a million times: a cycle. Both text-order cases fail, the nested empty-block case fails, and the existing 500-document property reports seven failures, including three cycles.

The review follow-up adds six focused empty-first-block cases. Against published head 0024dfcd, the same WrapNodesBlockLeaf.test.ts --maxWorkers=1 command reports 4 failed | 15 passed (19): the Box/list forward/backward cases reproduce t0, t3, t1 instead of t0, t1, t3. Both covered-empty cases already pass.

After

node_modules/.bin/vitest run --project unit packages/lexical-selection/src/__tests__/unit --maxWorkers=1
Test Files 9 passed (9)
Tests 1888 passed (1888)

This includes forward/backward selections, horizontal rules, nested empty blocks, a wrapping element, attached selection points with valid offsets, and the existing seeded property test now enabled as a normal test. The six new cases also check the empty quote position and covered empty-node identity, parent and sibling order. Independent follow-up QA ran WrapNodesBlockLeaf and WrapNodesInlineContent: 2 files / 1535 tests passed. These runs contain no skipped or expected-failure tests.

These checks were rerun for the follow-up and exited 0:

  • node_modules/.bin/tsc --noEmit

  • node_modules/.bin/tsc -p tsconfig.test.json --noEmit

  • node scripts/check-flow-types.mjs (Found 0 errors)

  • ESLint on the changed production and test files

  • Prettier on the three changed files

  • node scripts/changesets/check.mjs (Changeset check passed: 68 pending changeset(s) valid.)
  • The combined pnpm run ci-check attempt hit killed TypeScript processes (exit 137); the production/test type checks above were then run separately. The full unit/scripts-unit attempt was stopped (exit 130), so no full-suite result is claimed. Browser E2E tests were not run.

    Diff: 373 lines (+279 / -94) across 4 files Reviewer: wozhenbang2004 Review duration: 41548m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 373 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.354
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #9668"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.8% · Safe to merge
    22.8%
    Repository