Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): renderer crash on click into content-visibility-locked editor subtree (PRD-7974) (#3442)

serafin-garciac9c8f185f73e
diff --git a/packages/app/package.json b/packages/app/package.json
index 813c87a73..baff9490e 100644
--- a/packages/app/package.json
+++ b/packages/app/package.json
@@ -27,7 +27,7 @@
"measure:stress": "bash scripts/measure-stress.sh",
"measure:sweep": "bash scripts/measure-sweep.sh",
"perf:compare": "bash scripts/perf-compare.sh",
- "test:e2e": "playwright test tests/stress/ux-interactions.e2e.ts tests/stress/file-tree-create.e2e.ts tests/stress/file-tree-drag-to-root.e2e.ts tests/stress/file-tree-deselect-to-root.e2e.ts tests/stress/file-tree-collapse-spaced-folder.e2e.ts tests/stress/sidebar-file-list-fills.e2e.ts tests/stress/file-tree-sticky-collapse.e2e.ts tests/stress/create-then-rename-editable.e2e.ts tests/stress/find-replace.e2e.ts tests/stress/editor-tabs.e2e.ts tests/stress/crdt-stress.e2e.ts tests/stress/slash-command.e2e.ts tests/stress/paste-fidelity.e2e.ts tests/stress/fr-7a-disconnect-source-mode.e2e.ts tests/stress/docs-open.e2e.ts tests/stress/frozen-table-headers.e2e.ts tests/stress/asset-embed.e2e.ts tests/stress/asset-embed-advanced.e2e.ts tests/stress/asset-click-dispatch.e2e.ts tests/stress/handoff.e2e.ts tests/stress/multi-agent-presence.e2e.ts tests/stress/editor-mode-persistence.e2e.ts tests/stress/lint-config-toggle.e2e.ts tests/stress/plugin-enable-notice.e2e.ts tests/stress/schema-edit-fields-view.e2e.ts tests/stress/sidebar-search-pill.e2e.ts tests/stress/navigation-history.e2e.ts tests/stress/command-palette-semantic.e2e.ts tests/stress/agent-activity-panel.e2e.ts tests/stress/drop-pipeline-auto-open.e2e.ts tests/stress/command-palette-flicker.e2e.ts tests/stress/cm6-list-hanging-indent.e2e.ts tests/stress/ng7-rapid-nav-coherence.e2e.ts tests/stress/reveal-on-activate.e2e.ts tests/stress/selection-indicator.e2e.ts tests/stress/new-file-cross-doc-bleed.e2e.ts tests/stress/editor-mode-flip-cross-doc-bleed.e2e.ts tests/stress/editor-area-viewport-resize.e2e.ts tests/stress/qa-sidebar-responsive.e2e.ts tests/stress/prd-6955-reassertion-repro.e2e.ts tests/stress/prd-6955-reassertion-wedge.e2e.ts tests/stress/prd-6914-repro.e2e.ts tests/stress/showall-lazy-tree.e2e.ts tests/stress/tabs-component-strip.e2e.ts tests/stress/source-find-scroll.e2e.ts tests/stress/harness-app-warmth.e2e.ts tests/stress/qa-canary-authoring-both-modes.e2e.ts tests/stress/qa-canary-live-typing.e2e.ts tests/stress/keystroke-cadence-danger-space.e2e.ts tests/stress/jsx-unregistered-backspace-delete.e2e.ts tests/stress/jsx-unregistered-ime-concurrent.e2e.ts tests/stress/jsx-backspace-delete.e2e.ts tests/stress/link-authoring-bytes.e2e.ts tests/stress/link-authoring-apex.e2e.ts tests/stress/command-palette-parity.e2e.ts tests/stress/settings-search.e2e.ts tests/stress/chip-popover-positioning.e2e.ts tests/stress/docs-open-scroll-restore.e2e.ts tests/stress/file-tree-decoration-chip-strip-repro.e2e.ts tests/stress/grip-click-nodeselect.e2e.ts tests/stress/jsx-halo-semantics.e2e.ts tests/stress/jsx-image-body-click.e2e.ts tests/stress/jsx-prop-panel-placeholder.e2e.ts tests/stress/jsx-range-encompass-halo.e2e.ts tests/stress/jsx-wildcard-convert.e2e.ts tests/stress/markdown-lint.e2e.ts tests/stress/frontmatter-schema-badge.e2e.ts tests/stress/frontmatter-glob-picker.e2e.ts tests/stress/unified-problems.e2e.ts tests/stress/mid-type-recovery.e2e.ts tests/stress/observer-a-multi-client.e2e.ts tests/stress/outline-toolbar-occlusion.e2e.ts tests/stress/quiet-tree-hidden-doc.e2e.ts tests/stress/raw-mdx-fallback-onblur-upgrade.e2e.ts tests/stress/rename-noext-probe.e2e.ts tests/stress/show-ok-folders.e2e.ts tests/stress/source-polish.e2e.ts tests/stress/warm-skeleton-scroll-restore.e2e.ts tests/stress/props-toggle-scroll-preserve.e2e.ts tests/stress/yjs-no-dual-import.e2e.ts tests/stress/graph-panel-surfaces.e2e.ts tests/stress/asset-embed-real-fidelity.e2e.ts tests/stress/image-invalid-placeholder.e2e.ts tests/stress/local-target-audit.e2e.ts tests/stress/rename-content-preservation.e2e.ts tests/stress/rename-consolidation.e2e.ts tests/stress/outline-active-heading.e2e.ts tests/stress/outline-navigation.e2e.ts tests/stress/prd-7627-default-swatch.e2e.ts tests/stress/clipboard-dollar-math-source-fallback.e2e.ts tests/stress/source-mode-undo-keymap.e2e.ts tests/stress/timeline-recovered-restore.e2e.ts tests/stress/blank-line-preservation.e2e.ts tests/stress/landing-helpers.e2e.ts tests/stress/mode-switch-landing.e2e.ts tests/stress/mode-switch-ordinal-divergence.e2e.ts tests/stress/comment-annotation-visibility.e2e.ts tests/stress/qa-miles-edge-blanks.e2e.ts tests/stress/prop-upload.e2e.ts tests/stress/slash-command-auto-open.e2e.ts tests/stress/clipboard-relative-url-source-fallback.e2e.ts tests/stress/editor-split-view.e2e.ts tests/stress/language-load-failure.e2e.ts tests/stress/language-first-paint.e2e.ts tests/stress/user-text-direction.e2e.ts tests/stress/pseudolocale.e2e.ts tests/stress/language-picker.e2e.ts tests/stress/zh-hans-coverage-sweep.e2e.ts tests/stress/preview-tab-promotion.e2e.ts",
+ "test:e2e": "playwright test tests/stress/ux-interactions.e2e.ts tests/stress/file-tree-create.e2e.ts tests/stress/file-tree-drag-to-root.e2e.ts tests/stress/file-tree-deselect-to-root.e2e.ts tests/stress/file-tree-collapse-spaced-folder.e2e.ts tests/stress/sidebar-file-list-fills.e2e.ts tests/stress/file-tree-sticky-collapse.e2e.ts tests/stress/create-then-rename-editable.e2e.ts tests/stress/find-replace.e2e.ts tests/stress/editor-tabs.e2e.ts tests/stress/crdt-stress.e2e.ts tests/stress/slash-command.e2e.ts tests/stress/paste-fidelity.e2e.ts tests/stress/fr-7a-disconnect-source-mode.e2e.ts tests/stress/docs-open.e2e.ts tests/stress/frozen-table-headers.e2e.ts tests/stress/asset-embed.e2e.ts tests/stress/asset-embed-advanced.e2e.ts tests/stress/asset-click-dispatch.e2e.ts tests/stress/handoff.e2e.ts tests/stress/multi-agent-presence.e2e.ts tests/stress/editor-mode-persistence.e2e.ts tests/stress/lint-config-toggle.e2e.ts tests/stress/plugin-enable-notice.e2e.ts tests/stress/schema-edit-fields-view.e2e.ts tests/stress/sidebar-search-pill.e2e.ts tests/stress/navigation-history.e2e.ts tests/stress/command-palette-semantic.e2e.ts tests/stress/agent-activity-panel.e2e.ts tests/stress/drop-pipeline-auto-open.e2e.ts tests/stress/command-palette-flicker.e2e.ts tests/stress/cm6-list-hanging-indent.e2e.ts tests/stress/ng7-rapid-nav-coherence.e2e.ts tests/stress/reveal-on-activate.e2e.ts tests/stress/selection-indicator.e2e.ts tests/stress/new-file-cross-doc-bleed.e2e.ts tests/stress/editor-mode-flip-cross-doc-bleed.e2e.ts tests/stress/editor-area-viewport-resize.e2e.ts tests/stress/qa-sidebar-responsive.e2e.ts tests/stress/prd-6955-reassertion-repro.e2e.ts tests/stress/prd-6955-reassertion-wedge.e2e.ts tests/stress/prd-6914-repro.e2e.ts tests/stress/showall-lazy-tree.e2e.ts tests/stress/tabs-component-strip.e2e.ts tests/stress/source-find-scroll.e2e.ts tests/stress/harness-app-warmth.e2e.ts tests/stress/qa-canary-authoring-both-modes.e2e.ts tests/stress/qa-canary-live-typing.e2e.ts tests/stress/keystroke-cadence-danger-space.e2e.ts tests/stress/jsx-unregistered-backspace-delete.e2e.ts tests/stress/jsx-unregistered-ime-concurrent.e2e.ts tests/stress/jsx-backspace-delete.e2e.ts tests/stress/link-authoring-bytes.e2e.ts tests/stress/link-authoring-apex.e2e.ts tests/stress/command-palette-parity.e2e.ts tests/stress/settings-search.e2e.ts tests/stress/chip-popover-positioning.e2e.ts tests/stress/docs-open-scroll-restore.e2e.ts tests/stress/file-tree-decoration-chip-strip-repro.e2e.ts tests/stress/grip-click-nodeselect.e2e.ts tests/stress/jsx-halo-semantics.e2e.ts tests/stress/jsx-image-body-click.e2e.ts tests/stress/jsx-prop-panel-placeholder.e2e.ts tests/stress/jsx-range-encompass-halo.e2e.ts tests/stress/jsx-wildcard-convert.e2e.ts tests/stress/markdown-lint.e2e.ts tests/stress/frontmatter-schema-badge.e2e.ts tests/stress/frontmatter-glob-picker.e2e.ts tests/stress/unified-problems.e2e.ts tests/stress/mid-type-recovery.e2e.ts tests/stress/observer-a-multi-client.e2e.ts tests/stress/outline-toolbar-occlusion.e2e.ts tests/stress/quiet-tree-hidden-doc.e2e.ts tests/stress/raw-mdx-fallback-onblur-upgrade.e2e.ts tests/stress/rename-noext-probe.e2e.ts tests/stress/show-ok-folders.e2e.ts tests/stress/source-polish.e2e.ts tests/stress/warm-skeleton-scroll-restore.e2e.ts tests/stress/props-toggle-scroll-preserve.e2e.ts tests/stress/yjs-no-dual-import.e2e.ts tests/stress/graph-panel-surfaces.e2e.ts tests/stress/asset-embed-real-fidelity.e2e.ts tests/stress/image-invalid-placeholder.e2e.ts tests/stress/local-target-audit.e2e.ts tests/stress/rename-content-preservation.e2e.ts tests/stress/rename-consolidation.e2e.ts tests/stress/outline-active-heading.e2e.ts tests/stress/outline-navigation.e2e.ts tests/stress/prd-7627-default-swatch.e2e.ts tests/stress/clipboard-dollar-math-source-fallback.e2e.ts tests/stress/source-mode-undo-keymap.e2e.ts tests/stress/timeline-recovered-restore.e2e.ts tests/stress/blank-line-preservation.e2e.ts tests/stress/landing-helpers.e2e.ts tests/stress/mode-switch-landing.e2e.ts tests/stress/mode-switch-ordinal-divergence.e2e.ts tests/stress/comment-annotation-visibility.e2e.ts tests/stress/qa-miles-edge-blanks.e2e.ts tests/stress/prop-upload.e2e.ts tests/stress/slash-command-auto-open.e2e.ts tests/stress/clipboard-relative-url-source-fallback.e2e.ts tests/stress/editor-split-view.e2e.ts tests/stress/language-load-failure.e2e.ts tests/stress/language-first-paint.e2e.ts tests/stress/user-text-direction.e2e.ts tests/stress/pseudolocale.e2e.ts tests/stress/language-picker.e2e.ts tests/stress/zh-hans-coverage-sweep.e2e.ts tests/stress/preview-tab-promotion.e2e.ts tests/stress/cv-paint-lock-click.e2e.ts",
"test:e2e:install-browsers": "playwright install chromium webkit firefox",
"test:visual": "playwright test --config playwright.visual.config.ts",
"test:visual:update": "playwright test --config playwright.visual.config.ts --update-snapshots",
diff --git a/packages/app/src/components/EditorActivityPool.tsx b/packages/app/src/components/EditorActivityPool.tsx
index 87eb55807..3294f5c98 100644
--- a/packages/app/src/components/EditorActivityPool.tsx
+++ b/packages/app/src/components/EditorActivityPool.tsx
@@ -1457,7 +1457,9 @@ function ActivityEntry({
Stacking: the wrapper is position:relative + h-full. The
non-active child carries `.ok-mode-hidden`, which sets
`position:absolute; inset:0; pointer-events:none` alongside
- `content-visibility:hidden + contain-intrinsic-size`. That
+ `visibility:hidden` plus a rendering-update-deferred
+ `content-visibility:hidden` lock + `contain-intrinsic-size`
+ (full contract in globals.css §.ok-mode-hidden). That
takes the hidden editor out of normal flow so its 8000px
reserved intrinsic size doesn't size the wrapper or any
shared grid row (earlier grid-based stacking sized rows to
diff --git a/packages/app/src/globals.css b/packages/app/src/globals.css
index d7cb667d8..67f95ff41 100644
--- a/packages/app/src/globals.css
+++ b/packages/app/src/globals.css
@@ -5693,10 +5693,42 @@ html.electron-mode [data-slot="sidebar-inner"] {
sibling to 8000px and producing bottom whitespace on short docs. The
consuming dual-editor wrapper must be `position: relative` so this
absolute positioning resolves against it (see `EditorActivityPool.tsx`).
- `pointer-events: none` guards against stray hit-tests reaching hidden
- descendants before content-visibility's own hit-test skip applies. */
+ Paint-lock scheduling (renderer-survival contract): Blink hard-CHECKs —
+ killing the whole renderer process — when a mouse press's hit-tested
+ node gains a paint-locked ancestor within one input dispatch
+ (`hit_test_result.cc`, `DisplayLockUtilities::LockedAncestorPreventingPaint`;
+ the CHECK is present at Chromium HEAD). React discrete updates flush
+ inside event dispatch, so the className swap that applies this class can
+ land exactly there. `transition: content-visibility 0s 32ms allow-discrete`
+ defers the lock to a rendering update: discrete transitions flip TO
+ `hidden` at 100% of the transition (MDN transition-behavior), and the
+ document timeline's currentTime is fixed for the duration of a script
+ execution block (Web Animations), so a style recalc forced mid-dispatch
+ always computes the before-change value (`visible`) — the lock can only
+ form at "update the rendering", which never interleaves with an input
+ dispatch. Scope: the deferral covers the className-swap-on-existing-
+ element path (the crashing one). An element INSERTED already carrying
+ this class takes the lock in its first style recalc — transitions do
+ not start for an element absent from the previous style change event
+ (CSS Transitions §3) and there is no `@starting-style` here. That
+ first-insertion path is click-safe by construction (a freshly inserted
+ node cannot be an ancestor of a node hit-tested earlier in the same
+ dispatch), but do not rely on the deferral for newly mounted subtrees.
+ That deferred scheduling is the same rendering-update lock scheduling
+ `content-visibility: auto` has natively (see `.ok-chunk-wrapper` below).
+ `visibility: hidden` covers the deferral window: it removes the subtree
+ from hit-testing entirely (unlike `pointer-events: none`, which does not
+ invalidate a hit test captured earlier in the same dispatch), and it
+ stops the deactivated pane's paint at the same recalc that reveals the
+ activated sibling, keeping the flip flash-free while the lock is
+ pending. Do not drop any of the trio (content-visibility: hidden +
+ deferring transition + visibility: hidden) — the pairing is pinned by
+ `globals.cv-paint-lock.test.ts` and exercised at Playwright fidelity by
+ `tests/stress/cv-paint-lock-click.e2e.ts`. */
.ok-mode-hidden {
content-visibility: hidden;
+ transition: content-visibility 0s 32ms allow-discrete;
+ visibility: hidden;
contain-intrinsic-size: 0 8000px;
position: absolute;
inset: 0;
@@ -5764,7 +5796,15 @@ html.electron-mode [data-slot="sidebar-inner"] {
descendant CV:auto is moot until the ancestor returns to visible.
Scoped to `.ProseMirror` so source-mode CodeMirror DOM is untouched
- (CM6 has its own line-oriented viewport rendering). */
+ (CM6 has its own line-oriented viewport rendering).
+
+ Click-safety: cv:auto is safe under clicks because its lock state
+ changes only at rendering updates (never synchronously inside an input
+ dispatch) and hit-testing skips already-locked subtrees. Do not replace
+ `auto` with `hidden` here without the same deferred-lock + visibility
+ pair `.ok-mode-hidden` carries — an undeferred paint lock over
+ hit-testable editor content trips Blink's display-lock CHECK (see the
+ `.ok-mode-hidden` comment above). */
.ProseMirror .ok-chunk-wrapper {
content-visibility: auto;
contain-intrinsic-size: 0 var(--ok-cv-h, 80px);
diff --git a/packages/app/src/globals.cv-paint-lock.test.ts b/packages/app/src/globals.cv-paint-lock.test.ts
new file mode 100644
index 000000000..25f0c729f
--- /dev/null
+++ b/packages/app/src/globals.cv-paint-lock.test.ts
@@ -0,0 +1,183 @@
+/**
+ * Source-level guards for the content-visibility paint-lock deferral contract.
+ *
+ * Blink hard-CHECKs — killing the whole renderer process — when a mouse
+ * press's hit-tested node gains a paint-locked ancestor within one input
+ * dispatch (`hit_test_result.cc`, `LockedAncestorPreventingPaint`; present at
+ * Chromium HEAD). React discrete updates flush inside event dispatch, so any
+ * class that applies `content-visibility: hidden` to hit-testable editor
+ * content can land that lock mid-dispatch. The structural defense lives at
+ * the class definition in `globals.css`: every `content-visibility: hidden`
+ * declaration must be paired with
+ * (a) a `transition` on content-visibility with `allow-discrete` and a
+ * positive delay/duration — deferring lock formation to a rendering
+ * update (the document timeline is frozen within a script execution
+ * block, so a forced mid-dispatch recalc always computes the
+ * before-change `visible` value; scope: the deferral applies to
+ * class changes on EXISTING elements — an element inserted already
+ * carrying the class locks at first style recalc, which is
+ * click-safe only because a fresh node cannot be an ancestor of an
+ * earlier hit-tested one), and
+ * (b) `visibility: hidden` — making the subtree non-hit-testable before
+ * the lock can form (`pointer-events: none` is NOT sufficient: it does
+ * not invalidate a hit test captured earlier in the same dispatch).
+ * Additionally, no `content-visibility: hidden` may appear under a
+ * `.ProseMirror` scope at all — PM blocks are always live hit-test targets,
+ * and the chunk-wrapper rule relies on cv:auto's native rendering-update
+ * lock scheduling for its click-safety.
+ *
+ * These are source-level regex guards by necessity: the runtime behavior is
+ * only exercisable below-the-DOM in a real Chromium layout/paint engine —
+ * jsdom has no display-lock machinery (no style/layout engine, no rendering
+ * updates, no hit-testing), so no Vitest-tier runtime test can observe lock
+ * formation or its timing. The runtime rung that IS reachable is covered by
+ * `tests/stress/cv-paint-lock-click.e2e.ts` at Playwright fidelity (real
+ * Chromium, real mouse input); this file pins the CSS declarations that make
+ * that test pass so they cannot be silently dropped or new unpaired locks
+ * silently added.
+ */
+
+import { readdirSync, readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { describe, expect, test } from 'vitest';
+
+const RAW_CSS = readFileSync(join(__dirname, 'globals.css'), 'utf8');
+
+/** Comments stripped so prose mentioning declarations can't affect matching. */
+const CSS = RAW_CSS.replace(/\/\*[\s\S]*?\*\//g, '');
+
+interface RuleBlock {
+ selector: string;
+ declarations: string;
+}
+
+/**
+ * Leaf rule blocks (selector + declaration body without nested braces).
+ * Declaration blocks are always leaves; at-rule wrappers (@media etc.) are
+ * skipped as containers but their inner declaration blocks still match.
+ */
+function leafRuleBlocks(css: string): RuleBlock[] {
+ return [...css.matchAll(/([^{}]+)\{([^{}]*)\}/g)].map((m) => ({
+ selector: m[1].trim(),
+ declarations: m[2],
+ }));
+}
+
+/** Split a transition shorthand value on top-level commas (parens-aware). */
+function splitTopLevelCommas(value: string): string[] {
+ const segments: string[] = [];
+ let depth = 0;
+ let current = '';
+ for (const ch of value) {
+ if (ch === '(') depth++;
+ if (ch === ')') depth--;
+ if (ch === ',' && depth === 0) {
+ segments.push(current);
+ current = '';
+ } else {
+ current += ch;
+ }
+ }
+ segments.push(current);
+ return segments;
+}
+
+/** `content-visibility: hidden` specifically (not `visible` / `auto`). */
+const CV_HIDDEN = /content-visibility\s*:\s*hidden/;
+/** Bare `visibility: hidden` — must not match inside `content-visibility`. */
+const BARE_VISIBILITY_HIDDEN = /(?<![-\w])visibility\s*:\s*hidden/;
+/** A positive CSS time token (rejects bare `0s` / `0ms` / `0.0s`). */
+const POSITIVE_TIME = /(?:0*[1-9]\d*(?:\.\d+)?|0*\.0*[1-9]\d*)(?:ms|s)\b/;
+
+const blocks = leafRuleBlocks(CSS);
+const cvHiddenBlocks = blocks.filter((b) => CV_HIDDEN.test(b.declarations));
+
+describe('globals.css content-visibility paint-lock deferral contract', () => {
+ test('at least one content-visibility: hidden rule exists (guard is not vacuous)', () => {
+ expect(cvHiddenBlocks.length).toBeGreaterThanOrEqual(1);
+ });
+
+ test('.ok-mode-hidden keeps content-visibility: hidden (steady-state perf lock is intentional)', () => {
+ const modeHidden = blocks.find((b) => b.selector === '.ok-mode-hidden');
+ expect(modeHidden, '.ok-mode-hidden rule block must exist').toBeDefined();
+ expect(modeHidden?.declarations).toMatch(CV_HIDDEN);
+ });
+
+ test.each(
+ cvHiddenBlocks.map((b) => [b.selector, b] as const),
+ )('rule %j defers its paint lock via an allow-discrete transition with a positive delay/duration', (_selector, block) => {
+ const transitions = [...block.declarations.matchAll(/transition[^:;]*:\s*([^;]*)/g)].map(
+ (m) => m[1],
+ );
+ // Scope both assertions to the single top-level-comma segment that
+ // names content-visibility — matching the whole shorthand list lets a
+ // DIFFERENT property's segment satisfy them (e.g. `opacity 200ms ease,
+ // content-visibility 0s allow-discrete` has a positive time, but
+ // content-visibility's combined duration is 0s: no transition is
+ // created and the lock lands synchronously). Commas inside parens
+ // (cubic-bezier args) are not segment boundaries.
+ const cvSegment = transitions
+ .flatMap((value) => splitTopLevelCommas(value))
+ .find((segment) => /content-visibility/.test(segment));
+ expect(
+ cvSegment,
+ 'a content-visibility: hidden rule must declare a transition segment on content-visibility (defers lock formation to a rendering update)',
+ ).toBeDefined();
+ expect(
+ cvSegment,
+ 'the content-visibility transition segment must use allow-discrete (discrete properties do not transition otherwise)',
+ ).toMatch(/allow-discrete/);
+ expect(
+ cvSegment,
+ 'the content-visibility transition segment needs a positive delay or duration — with a combined duration of 0s no transition is created at all (CSS Transitions: starting requires combined duration > 0s), so the lock would form synchronously in the same style recalc',
+ ).toMatch(POSITIVE_TIME);
+ });
+
+ test.each(
+ cvHiddenBlocks.map((b) => [b.selector, b] as const),
+ )('rule %j pairs the paint lock with visibility: hidden (non-hit-testable during the deferral window)', (_selector, block) => {
+ expect(block.declarations).toMatch(BARE_VISIBILITY_HIDDEN);
+ });
+
+ test('no content-visibility: hidden under a .ProseMirror scope (PM blocks are live hit-test targets)', () => {
+ const offenders = cvHiddenBlocks.filter((b) => b.selector.includes('.ProseMirror'));
+ expect(offenders.map((b) => b.selector)).toEqual([]);
+ });
+
+ test('no cv:hidden outside globals.css (other stylesheets, Tailwind arbitrary properties, or JS style writes would bypass the paired-declaration guard)', () => {
+ // The pairing tests above parse globals.css only, so a paint lock
+ // minted anywhere else — a plain declaration in another bundled
+ // stylesheet (cmd-f.css, color-themes.generated.css, ...), a
+ // `[content-visibility:hidden]` Tailwind class, a
+ // `contentVisibility: 'hidden'` style prop, an
+ // `.contentVisibility = 'hidden'` assignment, or a
+ // `setProperty('content-visibility', 'hidden')` call — would carry
+ // none of the paired declarations. The lock must only ever be minted
+ // through a globals.css rule the pairing tests see. TS/TSX patterns
+ // are syntax-targeted (not bare `content-visibility: hidden`) so
+ // prose comments mentioning the declaration don't false-fail.
+ const TAILWIND_CV_HIDDEN = /\[\s*content-visibility\s*:\s*hidden\s*\]/;
+ const STYLE_PROP_CV_HIDDEN = /contentVisibility\s*[:=]\s*['"`]\s*hidden\s*['"`]/;
+ const SET_PROPERTY_CV_HIDDEN =
+ /setProperty\(\s*['"`]content-visibility['"`]\s*,\s*['"`]\s*hidden\s*['"`]/;
+ const srcRoot = __dirname;
+ const offenders: string[] = [];
+ for (const entry of readdirSync(srcRoot, { recursive: true, withFileTypes: true })) {
+ if (!entry.isFile() || !/\.(ts|tsx|css)$/.test(entry.name)) continue;
+ const filePath = join(entry.parentPath, entry.name);
+ const relPath = filePath.slice(srcRoot.length + 1);
+ if (relPath === 'globals.css' || relPath === 'globals.cv-paint-lock.test.ts') continue;
+ const content = readFileSync(filePath, 'utf8');
+ const isCss = entry.name.endsWith('.css');
+ const hit = isCss
+ ? CV_HIDDEN.test(content.replace(/\/\*[\s\S]*?\*\//g, ''))
+ : TAILWIND_CV_HIDDEN.test(content) ||
+ STYLE_PROP_CV_HIDDEN.test(content) ||
+ SET_PROPERTY_CV_HIDDEN.test(content);
+ if (hit) {
+ offenders.push(relPath);
+ }
+ }
+ expect(offenders).toEqual([]);
+ });
+});
diff --git a/packages/app/tests/stress/cv-paint-lock-click.e2e.ts b/packages/app/tests/stress/cv-paint-lock-click.e2e.ts
new file mode 100644
index 000000000..54d49095f
--- /dev/null
+++ b/packages/app/tests/stress/cv-paint-lock-click.e2e.ts
@@ -0,0 +1,128 @@
+/**
+ * Renderer-survival pin: a click into the editor must survive an ancestor
+ * gaining a `content-visibility` paint lock within the same input dispatch.
+ *
+ * Blink hard-CHECKs (`third_party/blink/renderer/core/layout/hit_test_result.cc`,
+ * `LockedAncestorPreventingPaint`) when a mouse press's hit-tested node has —
+ * or synchronously gains — a paint-blocked ancestor (`content-visibility:
+ * hidden`, or an off-viewport `content-visibility: auto`) between input
+ * dispatch and the click's default selection resolution. The whole renderer
+ * process dies; the desktop shell auto-reloads the window, which users
+ * experience as an app reboot. `pointer-events: none` on the locked subtree
+ * does NOT prevent it — the hit test is captured before the lock lands.
+ *
+ * OK stamps such locks onto hit-testable editor subtrees: `.ok-mode-hidden`
+ * (`content-visibility: hidden`, globals.css) on the inactive dual-editor
+ * pane via `EditorActivityPool.tsx`'s per-render className swap, and
+ * `.ok-chunk-wrapper` (`content-visibility: auto`, globals.css) on every
+ * top-level PM block via `chunk-wrapper-decoration.ts`. A React
+ * discrete-event render (mode flip, plugin/config cascade — e.g. toggling the
+ * markdownlint plugin, which clears block decorations across the whole doc)
+ * lands the class inside the click's dispatch, after the hit test but before
+ * selection resolution. This test reproduces that timing deterministically
+ * with a capture-phase mousedown listener stamping the app's own class on the
+ * app's own DOM, then asserts the renderer survived.
+ *
+ * Only the `.ok-mode-hidden` site is pinned here. The `.ok-chunk-wrapper`
+ * (cv:auto) site shares the same invariant and the same fix surface, but its
+ * crashing precondition — a paint-locked (off-viewport) wrapper as ancestor
+ * of a hit-tested node — is not deterministically constructible from script:
+ * cv:auto lock state flips only at rendering-update time, never inside an
+ * input dispatch (verified empirically: removing + re-applying the class with
+ * forced layout inside the mousedown does not paint-lock an on-viewport
+ * block, so no crash), and a click cannot land inside an off-viewport block.
+ *
+ * This seam only exists in a real Chromium layout/paint engine — jsdom has
+ * no display-lock machinery, so the pin lives at Playwright fidelity.
+ */
+
+import { randomUUID } from 'node:crypto';
+import type { Page } from '@playwright/test';
+import type { ApiHelpers } from './_helpers';
+import { expect, test } from './_helpers';
+
+const DOC_MARKDOWN = [
+ '# Survival doc',
+ '',
+ 'First paragraph with enough text to give the click a stable target.',
+ '',
+ 'Second paragraph so the doc has several top-level blocks.',
+].join('\n');
+
+/** Isolated per-test doc: create, seed, navigate, wait for editor mount. */
+async function setupDoc(page: Page, api: ApiHelpers): Promise<string> {
+ const docName = `test-cvlock-${randomUUID().slice(0, 8)}`;
+ await api.createPage(`${docName}.md`);
+ await api.testReset(docName);
+ await api.replaceDoc(docName, DOC_MARKDOWN);
+ await page.goto(`/#/${docName}`);
+ await page.waitForFunction(() => Boolean(window.__activeProvider?.isSynced), null, {
+ timeout: 15_000,
+ });
+ await page.waitForSelector('.ProseMirror:not(.composer-prosemirror) p');
+ return docName;
+}
+
+type ClickOutcome = 'alive' | 'renderer-crashed';
+
+/**
+ * Press-and-release on the first editor paragraph, then classify whether the
+ * renderer survived. Raced against the page `crash` event because a dead
+ * renderer can leave the in-flight input protocol call hanging (it would
+ * otherwise burn the whole test budget before the assertion runs); either
+ * signal classifies as `renderer-crashed` so the test fails on the assertion,
+ * not on infrastructure noise.
+ */
+async function clickFirstParagraphAndProbe(page: Page): Promise<ClickOutcome> {
+ const crashed = new Promise<ClickOutcome>((resolve) => {
+ page.once('crash', () => resolve('renderer-crashed'));
+ });
+ const target = page.locator('.ProseMirror:not(.composer-prosemirror) p').first();
+ const box = await target.boundingBox();
+ if (!box) throw new Error('editor paragraph has no bounding box');
+ const x = box.x + Math.min(24, box.width / 2);
+ const y = box.y + box.height / 2;
+ const clickAndProbe = (async (): Promise<ClickOutcome> => {
+ await page.mouse.move(x, y);
+ await page.mouse.down();
+ await page.mouse.up();
+ // Liveness probe: a crashed page rejects (or never answers) evaluate.
+ await page.evaluate(() => document.readyState);
+ return 'alive';
+ })().catch((): ClickOutcome => 'renderer-crashed');
+ return await Promise.race([crashed, clickAndProbe]);
+}
+
+test('click into the editor survives the inactive-pane paint lock (.ok-mode-hidden) landing mid-dispatch', async ({
+ page,
+ api,
+}) => {
+ await setupDoc(page, api);
+
+ // Arm: on the next mousedown (capture phase — before PM's own handlers and
+ // before Blink's default selection handling), stamp the app's own
+ // `.ok-mode-hidden` class on the visual editor pane — the same element
+ // EditorActivityPool's className swap targets — and force style+layout so
+ // the paint lock is committed inside this dispatch.
+ await page.evaluate(() => {
+ const pm = document.querySelector('.ProseMirror:not(.composer-prosemirror)');
+ const pane = pm
+ ?.closest('div.relative.flex-1')
+ ?.querySelector(':scope > div.h-full:not(.ok-mode-hidden)');
+ if (!(pane instanceof HTMLElement)) throw new Error('visual editor pane not found');
+ window.addEventListener(
+ 'mousedown',
+ () => {
+ pane.classList.add('ok-mode-hidden');
+ void pane.offsetHeight;
+ },
+ { capture: true, once: true },
+ );
+ });
+
+ const outcome = await clickFirstParagraphAndProbe(page);
+ expect(
+ outcome,
+ 'renderer must survive a click whose editor pane gains the .ok-mode-hidden paint lock during the same dispatch',
+ ).toBe('alive');
+});