Repository navigation
Web UI: do not update browser history on every keypress - #113596
Conversation
The query editor's `input` handler rewrote the browser-history entry and the URL on every character. For a long query that means structured-cloning the whole result snapshot through `replaceState`, base64-encoding the query into the URL hash, retitling the document and rebuilding the tab bar per keystroke; browsers also rate-limit `replaceState`. Now the handler keeps only the in-memory and persisted state in sync — the active tab's query and, through the parameter rebuild, its query parameters — and schedules the (already debounced) workspace save. Browser history and the URL are written when a query is successfully run (`saveHistory`) or on a structural tab change: switch, add, close, rename. Three places compensate for the entry no longer tracking every keystroke: - `closeTab` and `closeOtherTabs` fold the active tab's latest edit into its own entry before the tab goes away, exactly as `switchToTab`/`addTab` already do on leave, so a later Back that recreates the closed tab restores the draft rather than the stale last-run text; - `window.onpopstate` keeps a newer unrun draft instead of overwriting it with the navigated entry's older query. `tab.query !== tab.lastSavedQuery` is exactly "the editor holds text no entry has recorded", since `writeHistoryEntry` sets `lastSavedQuery` to whatever it wrote; - a run that completes after the editor moved on records the LAUNCH snapshot rather than the live draft. The entry is then a coherent query/params pair by construction. Writing the newer draft instead would pair it with the parameter map of the older text — the draft's own parameter rebuild (`updateQueryParams`) is asynchronous and need not have landed — so the URL would advertise a binding for a placeholder the draft no longer has. `syncParamsAfterRebuild` folds the rebuilt `param_*` inputs into the active tab, so the parameters follow the editor per keystroke without any history write; a new input is seeded from the tab's snapshot when no live input survived a restore, so folding cannot erase a saved binding. An unrun edit is not restored across a reload unless a run or a structural change followed it, or the debounced save flushed it — in which case `reconcileStartup`'s stale-reload branch restores it as editor text and never re-runs it. An unrun draft is never auto-executed. Pinned by scenarios in the existing `test_play_reconcile_startup` harness, which executes the real page script under `node`: a keystroke leaves the entry and URL untouched while still reaching the tab and `IndexedDB`; the persisted draft is restored, unrun, on reload; parameters follow the editor and leave no stale `param_x` in a later structural write; a run completing after an edit writes a coherent entry; Back/Forward keeps the draft; closing a tab folds it. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [4d41944] Summary: ✅
AI ReviewSummaryThis PR stops rewriting the Findings
Tests
Final VerdictChanges requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes4 object files changed (+18.71 KiB total), 0 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
Addresses the AI review finding: the parameter inputs are rebuilt
asynchronously after a query edit (most visibly while the first
`WebAssembly.instantiate` of the lexer is still in flight), so a
history-writing action in that window (`addTab`, `closeTab`, a database
change) snapshotted the PREVIOUS text's `param_*` inputs under the new
draft — e.g. recording `param_x=42` under `#SELECT 1` after editing
`SELECT {x:Int32}`, which Back/Forward, copied URLs and the next
persisted write then restored.
`captureActiveTab` now tracks which text the inputs describe
(`params_synced_text`, committed by `updateQueryParams`) and, on a
mismatch, re-derives the placeholder set synchronously from the captured
text (`tokenizeSync`, split out of `tokenize`), binding only surviving
names — live input values first, the tab's own saved snapshot as the
fallback seed, mirroring what the pending rebuild would eventually
commit. When even that is impossible (lexer not yet instantiated or the
text too large to tokenize), the tab's last committed snapshot is kept
instead of adopting values known to describe different text. The lexer
instantiation is kicked off eagerly at startup to shrink that window,
and the trusted parameter-edit path snapshots through `captureActiveTab`
for the same coherence.
The reconcile harness gains a scenario driving the race deliberately
(the close runs in the same synchronous turn as the edit): a removed
placeholder's binding must not appear in the folded entry, and a
surviving placeholder must keep its value.
|
🕵 The three CI failures on cf9f9aa are unrelated to this HTML-only change (all are server-side logical errors from stress/fuzzer runs):
None of the fixes are on master yet, so re-merging master would not clear them. |
…cribe The previous fix (f449c10) made `captureActiveTab` re-derive the placeholder set synchronously, but when even that is impossible — the first `WebAssembly.instantiate` of the lexer still in flight, a text too large to tokenize, or a tab restore that has not committed yet — the capture kept the previous text's snapshot and a structural write (`closeTab`, `addTab`, a database change) still published it: `{"query":"SELECT 1","params":{"x":"42"}}` for a draft that no longer has `{x:Int32}`. Track per tab which query text the snapshot was last coherently committed for (`paramsSyncedQuery`, stamped by every commit site: the capture, a restore, a popstate, `syncParamsAfterRebuild`, the startup URL reconciliation), and let `writeHistoryEntry` publish the snapshot only while it matches the recorded text — otherwise the entry records an empty parameter map, coherent by construction, while `tab.params` stays in memory as the seed the pending rebuild prunes and re-commits. The new `capture-races-lexer-load` harness scenario pins it: it delays `WebAssembly.instantiate` past startup settlement (the reviewer's reproducer) and folds a `closeTab` inside that window; on the previous code it fails with exactly the stale entry above. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113596&sha=3ff35b9f829b63cacf83160804ed63be3c1c99d6&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. It is unrelated to this HTML-only PR: |
|
A fix is in progress; I will link the PR here when it opens. Full root-cause write-up is on Short version: unrelated to this PR, and the regression is mine. PR #113225 Your reading that #113891 is a different site is correct, and I verified it independently: that |
… time
When a history-writing action lands while the tab's parameter snapshot is
not provably coherent with the recorded text (`paramsSyncedQuery` mismatch
and the synchronous re-derivation impossible — e.g. the first
`WebAssembly.instantiate` of the lexer still in flight), `writeHistoryEntry`
used to publish an empty parameter map. That fixed the removed-placeholder
case but regressed the surviving-placeholder one: editing
`SELECT {x:Int32}` to `SELECT {x:Int32} + 1` and closing the tab inside the
lexer-load window published `{}", so Back or a copied URL recreated the
draft without `x` although the placeholder survived and its value was
still valid.
Deciding which of the OLD text's bindings survive in the new one needs no
tokenizer: a real placeholder always contains the opener `{name:` literally.
`pruneParamsToText` keeps exactly the bindings whose opener appears in the
recorded text (whitespace-tolerant, identifier names only) and drops the
rest. The over-approximation — an opener inside a string literal or comment
keeps a binding the rebuild would prune — costs one unused `param_*` in a
URL, pruned again on restore, unlike dropping a live value.
The harness `capture-races-lexer-load` scenario now runs both edits: the
removed placeholder still publishes no binding, and the surviving one keeps
`x=42" (fails on the previous head with `params: {}").
When the lexer never becomes available (no `WebAssembly`, a failed load, or
a permanently too-large query), an edit advances `tab.query` and the
debounced `persist` records the new text with the OLD parameter snapshot in
`IndexedDB`. On reload, `restoreEditor`'s no-rebuild branch stamped that
never-rebuilt pair as coherent for the new text (`paramsSyncedQuery =
state.query`), so the startup history write republished the stale binding:
`history.state.params = {x: '42'}` and `?param_x=42` under a `SELECT 1`
that no longer has `{x:Int32}`.
Persist the snapshot's provenance (`paramsSyncedQuery`) with the tab record
and pass it through `activateTab` into `restoreEditor`, which now stamps
the text the committed values PROVABLY describe: the restored query when the
inputs were rebuilt for it (or when the state's own pair was coherent), and
the pair's original provenance otherwise. An incoherent pair then stays
incoherent across the reload, so `writeHistoryEntry` publishes it pruned
textually, exactly like the same-session lexer-load window: a removed
placeholder's binding is dropped, a surviving one keeps its value. For a
legacy record without the field the provenance defaults to null (fail-closed);
that costs nothing for a coherent pair, whose textual prune is a no-op. This
also covers the same-session variant: switching away from and back to a tab
edited during a no-lexer window no longer re-stamps its pair as coherent.
Adds the `disableWasm` harness knob (removes `WebAssembly` outright, so the
lexer never loads) and the `persisted-draft-stale-params` scenario: edit a
saved parameterized tab with the lexer unavailable, wait for the debounced
persist, reload, and assert the entry/URL carry no removed-placeholder binding
while a surviving placeholder keeps its value. The removed-placeholder variant
fails on the previous commit with exactly `?param_x=42#SELECT 1`.
|
🕵 The single CI failure on c40d67f — Stress test (arm_release), |
|
🕵 Both CI failures on 2c3f9fc are unrelated to this HTML-only change:
Neither fix has merged to master yet, so remerging the base would not clear these reds. The AI review reports no blocking issues on the current head. |
| /// `syncHistory` below publishes it. | ||
| const tab = getActiveTab(); | ||
| if (tab) { tab.params = getParamValues(); syncHistory(); } | ||
| if (tab) { captureActiveTab(); syncHistory(); } |
There was a problem hiding this comment.
Routing trusted param_* edits through captureActiveTab regresses the "query too large to tokenize" path. If a tab already shows param_x, the user edits the query into a text that makes updateQueryParams fail, and then edits that still-visible param_x, captureActiveTab returns at extractQueryParamNamesSync(tab.query) === null without adopting the live DOM value. syncHistory() and the scheduled persist() then keep the old tab.params.x, so a reload or quick close loses the user's new value even though the input they just edited stayed on screen. We still need either to preserve trusted DOM values for surviving on-screen names when re-derivation fails here, or to clear those stale inputs once the query-side rebuild fails so this handler cannot persist the old snapshot.
There was a problem hiding this comment.
This would be too much.
The query editor's
inputhandler rewrote the browser-history entry and the URL on every character. For a long query that means structured-cloning the whole result snapshot throughreplaceState, base64-encoding the query into the URL hash, retitling the document and rebuilding the tab bar per keystroke; browsers also rate-limitreplaceState.Now the handler keeps only the in-memory and persisted state in sync — the active tab's query and, through the parameter rebuild, its query parameters — and schedules the (already debounced) workspace save. Browser history and the URL are written when a query is successfully run (
saveHistory) or on a structural tab change: switch, add, close, rename.Three places compensate for the entry no longer tracking every keystroke:
closeTabandcloseOtherTabsfold the active tab's latest edit into its own entry before the tab goes away, exactly asswitchToTab/addTabalready do on leave, so a later Back that recreates the closed tab restores the draft rather than the stale last-run text;window.onpopstatekeeps a newer unrun draft instead of overwriting it with the navigated entry's older query.tab.query !== tab.lastSavedQueryis exactly "the editor holds text no entry has recorded", sincewriteHistoryEntrysetslastSavedQueryto whatever it wrote;updateQueryParams) is asynchronous and need not have landed — so the URL would advertise a binding for a placeholder the draft no longer has.syncParamsAfterRebuildfolds the rebuiltparam_*inputs into the active tab, so the parameters follow the editor per keystroke without any history write; a new input is seeded from the tab's snapshot when no live input survived a restore, so folding cannot erase a saved binding.An unrun edit is not restored across a reload unless a run or a structural change followed it, or the debounced save flushed it — in which case
reconcileStartup's stale-reload branch restores it as editor text and never re-runs it. An unrun draft is never auto-executed.Pinned by scenarios added to the existing
test_play_reconcile_startupharness, which executes the real page script undernodeagainst a live server: a keystroke leaves the entry and URL untouched while still reaching the tab andIndexedDB; the persisted draft is restored, unrun, on reload; parameters follow the editor and leave no staleparam_xin a later structural write; a run completing after an edit writes a coherent entry; Back/Forward keeps the draft; closing a tab folds it.This replaces #109360, which took the same policy but reconstructed synchronously, at each remaining write site, what the per-keystroke write used to repair asynchronously — including an 80-line hand-written re-implementation of
src/Parsers/Lexer.cpp's quoting, heredoc and comment rules in JavaScript. Keeping the parameters in sync per keystroke and recording the launch snapshot on a divergent run removes the need for any of it:programs/server/play.htmlhere is +43/-20 code lines against +169/-27 there, with no new persisted state, no second lexer and no new CI image dependency.Related: #109360
Related: #113595
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
In the Web UI, the browser history and the URL are no longer updated on every keypress; they are recorded when a query is successfully run or on a tab change.
Documentation entry for user-facing changes
Version info
26.8.1.1104(included in26.8and later)