perf: tag the center column instead of a :has() selector; stop re-stringifying the editor doc per keystroke

The bottom-push rule anchored on #root :has(> [data-slot=conversation]):
a :has() match cache invalidates on every #root subtree mutation, and
the streaming chat mutates that subtree constantly — every layout-push
frame (the bottom drag writes --dsh-sidebar-height per frame) paid a
whole-document selector re-evaluation. The shell's locator (which
already holds the measured column node for the ResizeObserver) now
tags it with [data-dsh-center-col]; the rule evaluates once per node.
The tag retargets with the ref on boot swap / HMR node replacement and
is removed on unmount; the drag lane pins exactly-one-tagged-node and
its identity as the conversation slot wrapper's parent. The dead
[data-pane] branch (renamed away in alpha hosts) is gone.

TextEditor: the CodeMirror updateListener re-stringified the WHOLE
document into React state on every keystroke (O(docLength) per key,
re-rendering the shell per key). The listener now only flips the dirty
flag; the preview's draft is snapshotted from the live view when
entering preview (or on a content swap), and save() already reads the
live document.
This commit is contained in:
Menghuan1918 committed 2026-09-01 16:01:34 +08:00
1 parent c7d58c9b25
commit cf542d6318
6 files changed
+63 -47

No files matched your search

+16 -23
View File
@@ -612,35 +612,28 @@ test('bottom panel never flashes full-width after a width drag release (issue #2
}
})
test('the bottom-push anchor resolves through the composite selectors (at least one; same element when both)', async ({ page }) => {
// layout.css pushes the bottom panel via the center column. The selector
// is COMPOSITE on purpose: `[data-pane="conversation"]` (0.1.x naming)
// and `:has(> [data-slot="conversation"])` (rc.8-era naming) — HOST
// VERSIONS MAY RENAME THE ATTRIBUTE (issue #208 comment / PR #226), so
// the contract is "at least one resolves", and when both resolve they
// must hit the SAME element (otherwise the push would land twice).
test('the bottom-push anchor resolves through the shell-written center-column tag', async ({ page }) => {
// layout.css pushes the bottom panel via the center column, anchored on
// the [data-dsh-center-col] tag the Sidebar shell's locator writes onto
// the measured column node (Sidebar.tsx locate — the slot wrapper
// [data-slot="conversation"]'s parent). The tag must sit on exactly ONE
// node: a stale tag on a swapped-out node (boot swap / HMR) would leave
// the push rule anchorless or doubled.
await page.goto(PAGE_URL, { waitUntil: 'domcontentloaded' })
await expect(page.locator('[data-dsh-better-sidebar]')).toBeAttached({ timeout: 90_000 })
await expect
.poll(async () => page.evaluate(() => document.querySelectorAll('#root [data-dsh-center-col]').length), { timeout: 90_000 })
.toBe(1)
const anchors = await page.evaluate(() => {
const a = document.querySelector('#root [data-dsh-frame] > [data-pane="conversation"]')
const b = document.querySelector('#root :has(> [data-slot="conversation"])')
const frame = document.querySelector('#root [data-dsh-frame]')
const tagged = document.querySelector('#root [data-dsh-center-col]')
const slotParent = document.querySelector('#root [data-slot="conversation"]')?.parentElement ?? null
return {
a: a !== null,
b: b !== null,
same: a !== null && b !== null && a === b,
frameChildren: frame !== null
? [...frame.children].map(el => `${el.tagName}[${[...el.attributes].map(attr => attr.name).filter(name => name.startsWith('data-')).join(',')}]`)
: [],
tagged: tagged !== null,
same: tagged !== null && slotParent !== null && tagged === slotParent,
}
})
expect(
anchors.a || anchors.b,
`at least one bottom-push anchor must resolve on this host (frame children: ${anchors.frameChildren.join(' / ') || 'no [data-dsh-frame]'})`,
).toBe(true)
if (anchors.a && anchors.b) {
expect(anchors.same, 'both selectors must hit the SAME center-column element').toBe(true)
}
expect(anchors.tagged, 'the tagged center column must resolve').toBe(true)
expect(anchors.same, 'the tag must sit on the conversation slot wrapper\'s parent (the measured column)').toBe(true)
})
/* ── bottom-strip drag with the right panel CLOSED must not touch the host
+8 -4
View File
@@ -9,9 +9,13 @@ import { describe, expect, it } from 'vitest'
const css = readFileSync('src/client/layout.css', 'utf8')
describe('layout.css conversation column', () => {
it('targets the AppFrame center column', () => {
expect(css).toContain('[data-pane="conversation"]')
expect(css).toContain('[data-slot="conversation"]')
it('targets the AppFrame center column through the shell-written tag', () => {
// The bottom-push rule anchors on the [data-dsh-center-col] tag the
// Sidebar shell's locator writes onto the measured column node (see
// Sidebar.tsx locate) — not on a `:has()` selector, whose cache
// invalidates on every #root subtree mutation (the streaming chat).
expect(css).toContain('[data-dsh-center-col]')
expect(css).not.toContain(':has(')
})
it('allows the center column to shrink and wrap long tokens', () => {
@@ -21,7 +25,7 @@ describe('layout.css conversation column', () => {
it('leaves overflow ownership to the host conversation descendants', () => {
const conversationRule = css.match(
/#root \[data-dsh-frame\][\s\S]*?\{([\s\S]*?)\n\}/,
/#root \[data-dsh-center-col\][\s\S]*?\{([\s\S]*?)\n\}/,
)?.[1]
expect(conversationRule).toBeDefined()
expect(conversationRule).not.toMatch(/(?:^|[;\s])overflow\s*:/)