Repository navigation
Add a notebook mode to the Web UI - #115378
Conversation
A tab in the Web UI can now be turned into a notebook — an ordered sequence of cells, each either a query with its own result or a block of Markdown text — in the spirit of Jupyter, Observable, Hex and Deepnote. Once a query has produced a result, a large, deliberately muted `[+]` appears under it and expands into the two kinds of cell that can be added: query or text. Adding the second cell activates notebook mode for that tab; notebook mode is per tab, so one tab can be a notebook while another stays a plain single-query editor. From two cells on, every cell gets a header with its position, its kind, a run-status dot, and the editing actions: run, edit, insert a cell before, move up/down, delete. There is still exactly one query editor on the page — the full one with its highlighting backdrop, autocompletion and query-parameter inputs. In notebook mode it is docked into whichever query cell is active; every other query cell shows its query collapsed to a single syntax-highlighted line, with runs of whitespace reduced to one space, no background of its own, and the tail faded out on the right. Results are shown more compactly: a smaller font and a pane of at most a quarter of the viewport that scrolls internally instead of pushing the notebook down the page. A text cell shows its Markdown source with the markers highlighted while it is being edited, and the rendered Markdown once editing finishes; clicking the rendered text switches back to the source. Raw HTML is escaped and link targets are restricted to `http`, `https`, `mailto` and relative URLs. Internally, the query text, parameters and result snapshot moved from the tab to the cell. `tab.query` / `tab.result` / `tab.resultEl` are now accessors onto the cell the editor is docked in, so the editor, history, URL and persistence code is unchanged; a run captures its own cell, so moving on to another cell mid-run does not redirect the response. The whole notebook is persisted in IndexedDB alongside the rest of the workspace, and history entries record the cell they describe. A tab holding a single cell renders exactly as before: no cell chrome, the editor in its usual place, the result at full height.
A text cell now uses the same monospace family as a query, both while its Markdown source is being edited and once it is rendered, so the notebook reads as one document and the font does not jump when a cell switches between the two states. A code span is set apart by its tint alone, since the surrounding text is already monospace. Two alignment fixes fall out of this, both affecting the transparent text area laid over its highlight backdrop: - Add `.md-backdrop` to the coarse-pointer rule that raises every layer mirroring a text area's metrics to 16px. The `textarea` selector there already covered the text area itself, so on a touch device the two layers were set at different sizes. - Build the backdrop by joining the highlighted lines rather than appending a newline to each. The old form emitted one line more than the source, leaving the backdrop a line taller than the text area it sizes itself against.
# Conflicts: # programs/server/play.html
In notebook mode the docked editor is now shown only while it has the focus. Losing focus collapses that cell to its one-line preview, so a notebook you are reading shows no open text areas at all; clicking a collapsed query gives the editor back. Focus moving WITHIN the editor — to a query-parameter input or a completion candidate — does not count as leaving, so the decision is deferred past `blur` (which fires before focus lands anywhere). A click on Run is exempt too: the launched run focuses the editor straight back to select the statement it executes, and collapsing in between would flash the preview for one frame. Because a hidden text area cannot take focus, the paths that mean "let the user type" go through `focusEditor`, which reveals it first. Layout, alongside it: - Cells lose their left border and indent. They are separated by whitespace alone, so the notebook reads as one flowing document and a result lines up with the query above it. Which cell holds the editor is already evident — it is the one that is not collapsed. - A result's table is now the scroll container itself, on both axes (`--result-max-height` / `--result-max-width` / `--result-overflow`), instead of a wrapper around it: the scrollbars sit at the table's own edges, the column headers pin to the top of the table, and a wide result no longer widens the whole page. The scrollbars are thin, as the database panel and the expanded-cell view already are. - The header reserves just enough room above the column name for the column's type, which is drawn there rather than above the header, where a bounded table would clip it away. The space belongs to the opaque, sticky header, so no row shows through it at any scroll position — the header is pulled up by 1px because `border-collapse` leaves a stuck cell without its own top border, through which the row underneath would otherwise show. The gap above the table is a margin, outside the scroll container, so it shows the page through it and does not scroll away. - The last column's resize grip no longer overhangs the table's right edge in a bounded table, where those few pixels became a horizontal scroll range on a table that otherwise fits exactly. Single-cell mode renders exactly as before: every knob above is a custom property that defaults to the previous value.
The resize grip is a plain div inside `#query_div`, so pressing it moved the focus to `<body>`. In notebook mode that reads as leaving the editor, which collapsed the cell the instant the drag began, taking the grip with it. The grip's `pointerdown` now prevents the default action, so the focus stays in the text area; `pointermove`/`pointerup` are unaffected, so the drag itself works as before. The deferred blur check also treats a pointer held down anywhere on the editor's own surface as "not left" and takes the focus back, so any other non-focusable chrome added there later cannot reintroduce this.
In notebook mode the Run / Run all / progress / copy / download row now docks under the active cell's query, between it and its result, instead of staying in the page header. That is where the run it describes belongs, it makes it obvious how to run a given cell, and it supplies the separation between a query and its table by itself. The row stays in place when the cell collapses, so a running cell keeps showing its progress and a collapsed cell can still be re-run. The column type hint goes back to hanging BELOW the header rather than inside it, so the header keeps its ordinary height. The reserved strip added for it in the previous commit is gone; a bounded table's header sits at the very top of its own scroll container, so the hint has to hang the other way regardless, and doing it that way costs no header height. Two things this move exposed, fixed here: - `#run` gets `form="controls"`, so the implicit submission that runs a query still works once the button is outside the form's subtree. (The connection inputs already carry the attribute for the same reason.) - The download drop-down positioned itself from client rects without adding `#main`'s scroll offsets, so it landed at the wrong place on a scrolled page. Harmless while the button lived in the sticky header; now that it rides with the active cell, it is normally well down a scrolled page.
…lish The header's top border no longer disappears when the table is scrolled. It used to be hidden deliberately: with `border-collapse` the table paints the cell borders and a stuck header does not carry them along, so the row scrolling underneath showed through that one-pixel line, and the header was pulled up by 1px to cover it. Instead the top border is now drawn on the header cells themselves, so it travels with them and covers the line — the same reason `td.pinned-column` draws its side edges with a shadow. The header sticks flush with the table's top edge again. The strip deliberately does not overhang the last column: that pixel lands outside the table, and a bounded table counts it as scrollable overflow, which showed up as a one-pixel horizontal scroll on a table that fits exactly. Alongside it: - The cell header reads `1. Query` rather than `1 · QUERY`: no caps, no middle dot. The status dot marks only a run in flight or a failure; a finished cell is not marked, its result being right below it. - The Run row is part of the editor and now appears and disappears with it, rather than staying behind when the cell collapses. - Table cell padding is in `em`, so it scales with the font: a result shown at 85% in a notebook cell tightens instead of keeping the padding of a full-size table. Identical to the previous `rem` values at the default size. - A result can be resized by dragging its bottom edge, exactly as the query editor is, and so can a text cell's Markdown editor: the query editor's drag handle is now a shared helper. A result's height is remembered for the cell and re-applied to the elements a later run or restore builds. Raw (non-table) output is bounded by the same variables as a table, so the height applies whatever the format is. - The big [+] is square rather than a wide bar.
A previous commit added a `th:last-child .resizer` rule for the last column's grip and, in doing so, split the `.resizer` rule it was inserted after: `cursor: col-resize`, `user-select: none` and `height: 100%` ended up inside the new `th:last-child` block. Every other column's grip was therefore zero pixels tall, with no hit area and no resize cursor, so only the last column could be resized. This affected both notebook mode and the ordinary single-query view. The three declarations go back where they belong; the last-column rule keeps only the `right` offset it was added for.
… scrollbar Pressing anything in the docked Run row blurred the editor, and the deferred collapse then hid the row before the `click` arrived — so the theme switch did nothing in notebook mode, and the copy, download and Logs/Metrics controls would have behaved the same way. Only Run and Run all worked, because they are buttons that take the focus, and were special-cased. That special case is replaced by an explicit notion of the editor's surface: the editor, its parameter inputs, the Run row docked with it, and the download menu that row opens (which lives elsewhere in the DOM so it can be positioned freely). Focus landing anywhere in it, or a pointer held down on any non-focusable part of it, is not the user moving on, so the cell stays expanded and the control keeps the pointer. Also: while the active tab is a notebook, the page keeps its vertical scrollbar (`overflow-y: scroll` on `#main`). A notebook's height changes constantly — cells expand and collapse as they take the editor, results are resized, cells are added and removed — and letting the scrollbar come and go with it shifted the whole layout sideways each time.
# Conflicts: # programs/server/play.html
|
Workflow [PR], commit [4ec7c56] Summary: ✅
AI ReviewSummaryThis PR adds notebook mode to Findings
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 4ec7c56.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +154 lines in 43 files (-137 lines lost coverage) · Details |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes3 object files changed (+99.65 KiB total), 0 added.
719 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. |
…e running cell Two run-lifecycle defects found by the review of the notebook mode. The cell header's `▶` called `postAll` directly, bypassing the `activeInFlight` / `cancel` gate the Run button goes through. A second request was therefore started while the first was still streaming, and `tab.controller` was overwritten with the new one, leaving the earlier query running with no `Stop` handle. `cancel` is split into `cancelTabRun`, which takes the tab, and `runCell` now ends the tab's current run through it before launching, so a tab still has exactly one query in flight. The shared run row (`Run`/`Stop`, the progress bar and its resource meters, the Logs/Metrics toggles and the download/copy buttons) followed `activeCell`, while the response of a run keeps streaming into the cell captured at `beginFlight`. Moving the editor to another cell mid-run therefore took the `Stop` row away from the running query, and `syncActiveTabChrome` repainted the bar and the meters from the idle cell, erasing the live progress of a query that was still going. The chrome now follows `chromeCell` — the running cell while the tab is in flight, the active cell otherwise — and `endFlight` repaints it once the run is over. `test_play_image_preview` is updated for the renamed `clearPanel` (now `clearCell`, taking a cell) and for `postMulti` taking the cell it renders into.
`clearPanel` gained the Download/Copy withdrawal on `master` while it became the per-cell `clearCell` here; the new clearing is carried over onto the cell, and its shared repaint runs through `paintDownloadCopy` for the cell that owns the chrome. `test_play_image_preview` gets the same treatment for the scenario `master` added.
|
🕵 The stress-test red ( The |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
…URLs to the cell Three fixes for the notebook mode, from the AI review of `68427b1025a1`: - The shared run row is docked under `chromeCell(tab)`, but its `Logs` / `Metrics` handler still wrote through `activeCell(tab)` and the logo was still repainted from `tab.logoVisible` (an accessor onto the active cell). Moving the editor off a still running cell therefore retargeted those toggles at the newly active cell's result and could regrow the idle logo over a running `Run all` row. Both now read `chromeCell`, like the rest of that row. - `colorModes` / `pinnedColumns` are per cell, but the toggle repainted every `query-result` of the whole tab and `persistColorModes` / `persistPinnedColumns` wrote through the ACTIVE cell, so a toggle made in another cell of the notebook never reached its own result snapshot and was lost on reload. The repaint is now scoped to the owning cell (`_sharedColorScope`, which still covers all the tables of that cell's `Run all`), and both persist functions take the owning cell: they record onto its snapshot always, and re-stamp the URL and the history entry only when it is the active cell, which is what those describe. The now unused `activeColorModes` / `activePinnedColumns` helpers are dropped. - `safeMarkdownUrl` whitelisted only `#`, `/`, `./` and `../`, rejecting ordinary relative targets like `[guide](guide.md)`, `` or `[q](?q=1)`, which contradicts the documented text-cell contract. It now allows any scheme-less, authority-less URL and rejects a named scheme other than `http` / `https` / `mailto` as well as a protocol-relative `//host` (the scheme is decided on a copy with ASCII whitespace and control characters stripped, so `java<tab>script:` cannot slip past). Tested by a new `test_play_notebook` harness, which runs the real page script in a stubbed browser environment and drives the notebook: a mid-run cell switch followed by a `Logs` toggle, a color/pin toggle in a non-active cell with the persistence round-trip, and the Markdown URL policy. All three scenarios fail against the previous page. `04548_play_ui_framing_fallbacks` pins the new source lines.
…and stop clearing the shared row after a repaint Two findings of the AI review on `programs/server/play.html`. 1. `serializeCellsForHistory` counted only the result snapshots against `HISTORY_NOTEBOOK_BUDGET`, so a text-heavy notebook could exceed the browser's per-entry history-state limit through its Markdown alone and `writeHistoryEntry` fell through to the `cells: []` fallback, after which `Back` could recover only the active query cell of a closed tab. The budget now covers the whole serialized cell (query, parameters, text, result): result snapshots are stripped first, largest first, then Markdown text is trimmed by no more than the remaining excess. Queries are never cut, because a truncated statement can be a different, still valid statement. `writeHistoryEntry` gained a rung between "results stripped" and "no notebook copy" that drops the Markdown text but keeps the structure and every query. 2. `deleteCell` stopped a run in the deleted cell with an unconditional `progressEl.clear()` after `endFlight` had already repainted the shared row from the surviving active cell, wiping that cell's stats. The delete path now goes through `cancelTabRun`, whose own trailing clear is made conditional on `cellOwnsChrome(cell)`: the widget is cleared only while it still describes the stopped cell. Tests: `notebook_harness.js` gains `delete-running-cell-keeps-active-chrome` and `history-budget-covers-text`, and `stop-after-editor-moved-repaints-chrome` now records the calls made on the shared widget. All three fail against the previous page. `04548_play_ui_framing_fallbacks` expects five `cancelTabRun(tab);` call sites. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 @groeneai, investigate the failures on
|
|
Both failures already have an open fix of mine, so I am linking them rather than opening new PRs.
|
Conflicts in `programs/server/play.html`, all resolved in favour of master's single layout while keeping the notebook structure: - markup: the connection `#inputs` now live in the drop-down (master); the editor keeps its `#editor-home` wrapper and gains master's `Format` button; - `renderTabBar`: `syncConnectionUI` is gone (master), `focusEditor` kept; - `saveHistory`: `cell.result` kept with master's comment; - startup blank-tab pruning comment merged. Reconciled with master's new code: - master dropped the `controls_elem` declaration that the notebook run row still needs; re-declared as `controls_form_elem` (so `05234`, which pins that the connection inputs never move, keeps its meaning); - Save / Load of tabs as Markdown now covers every cell of a notebook: each query cell as before (query, parameters, result tables), each Markdown cell as a `markdown` code block; Load turns every block under a tab heading into a cell. A single-query tab saves exactly as before. `05233` updated; - the `Format` button also drops its result when the editor moved to another cell while the request was in flight. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…once Adding, editing or deleting a Markdown cell, moving a cell, or deleting an inactive query cell only armed the 400 ms `scheduleSave` debounce. No cell activation or run follows such a change, so nothing else recorded it: a reload inside that window found the pre-change notebook both in `IndexedDB` and in the current history entry (whose `cells` recreate the tab on Back/Forward). - `commitNotebookChange(tab)` refreshes the active tab's history entry in place and saves at once (`saveNow`, which takes over a pending debounce); used by `addCell` (Markdown cell), `moveCell`, `deleteCell` and the Markdown editor's `blur`. Keystrokes stay debounced, like the query editor's. - `addCell` for a query cell saves once the activation has loaded the new cell. - A save still pending when the page goes away is started on `pagehide`. New `notebook_harness.js` scenarios: `notebook-change-survives-immediate-reload` (each change snapshotted 30 ms after it and rebooted; all 8 checks fail on the previous `play.html`), and `save-load-round-trips-notebook` for the notebook-aware Save / Load from the master merge. `waitForNextPersist` now waits until no save is pending, since a notebook change no longer leaves a debounced one behind. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 @groeneai, thanks. Both reds on |
|
Both attributions are right. Where the two stand, measured now:
|
Conflict in the `Format` button handler of `programs/server/play.html`: master added the `connectionGeneration` check; the branch checks that the editor is still docked in the same notebook cell. Both checks are kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`buildTabsMarkdown` wrote `cell.params` verbatim, while `loadTabsFromMarkdown` stamps the loaded pair as coherent (`paramsSyncedQuery = query`). A cell whose bindings were committed for an older text therefore had them saved, and made durable on Load, under the new text. Prune them against the text with `pruneParamsToText` unless `paramsSyncedQuery` matches, as `writeHistoryEntry` does, and cover it with the `save-drops-stale-parameters` scenario. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged All five The |
| /// Restore which notebook cell this entry belongs to before anything is written through the | ||
| /// tab's cell accessors. A cell deleted since the entry was written simply keeps the tab's | ||
| /// current cell. | ||
| if (event.state.cellId && tab.cells.some(c => c.id === event.state.cellId && c.type === 'query')) { |
There was a problem hiding this comment.
This only restores cellId for an already-open notebook tab; the full notebook snapshot in event.state.cells is still only applied inside resolveTabForState when the tab had been closed and recreated. That leaves same-tab Back/Forward broken for notebook structure.
Concrete trace:
- Start with two query cells and visit both so an older entry carries
state.cellsfor the two-cell notebook. - Delete one cell, which rewrites only the current entry in place.
- Hit Back to the older entry without closing the tab.
Expected: the older entry rehydrates the two-cell notebook.
Actual: tab.cells stays in its newer one-cell shape, because this branch only flips activeCellId. The later tab.materialized = false does not rescue the result path either — materialized is per-cell now — so activateTab also keeps the newer live DOM instead of re-rendering the entry snapshot.
Can we reapply deserializeCells(event.state) (or otherwise patch tab.cells) on the already-open-tab path before activateTab, and clear each query cell's materialized flag so the entry's snapshots are rematerialized too?
alexey-milovidov
left a comment
There was a problem hiding this comment.
Surprised to see an ad-hoc Markdown renderer, we likely already have a library that we use in /docs. But everything else is ok.
Approved.
…ress Master's client progress rework (ClickHouse#118536, ClickHouse#123549) moved the CPU, memory and temp-disk reads of `writeProgress` into one `getProfileSnapshot()` call under `profile_events_mutex` and added a "waited" meter. The IO rate now comes from the same snapshot (`ProfileSnapshot::io_rate`), so it is read together with the other values, and the IO counters are summed next to the other `INCREMENT` rows in `ClientBase::onProfileEvents`. The Web UI notebook mode (ClickHouse#115378) moved the resource-meter state from the tab to the cell, so both `payloadMeter` callbacks now add to `cell.resources`. Left as merged, the live one would read `tab.resources`, which no longer exists, and throw on the first result packet. 04548 greps the new spelling and keeps master's new checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds a notebook mode to the Web SQL UI (
/play): a tab can become an ordered sequence of cells, each either a query with its own result or a block of Markdown text — the shape of document Jupyter, Observable, Hex and Deepnote use, and for the same purpose: keeping a chain of queries, and the reasoning between them, on one page.How it works
A tab starts as a single query cell and looks exactly as it always has — no headers, no cell chrome, no notebook. Once a query has produced a result, a large muted
[+]appears under it and expands into the two kinds of cell that can be added, query or text. Adding the second cell is what turns notebook mode on, and it is per tab: one tab can be a notebook while another stays a plain single-query editor, and each tab remembers its own notebook across reloads.From two cells on, each cell gets a header with its position and kind (
1. Query,2. Text) and the editing actions: run, edit, insert a cell before, move up/down, delete.There is still exactly one query editor on the page — the full one, with its highlighting backdrop, autocompletion and query-parameter inputs. In notebook mode it is docked into whichever query cell is active, and shown only while it has the focus; as soon as focus leaves, that cell collapses to its query on a single line, syntax highlighted, whitespace runs reduced to one space, fading out on the right. The Run / progress / copy / download row docks under the query being edited, between it and its result, and appears and disappears with the editor.
Results are more compact: a smaller font with the cell padding scaled to match, and a table of at most a quarter of the viewport that is its own scroll container on both axes, so its (thin) scrollbars sit at its own edges and a long or wide result neither pushes the notebook down the page nor widens it. Results and Markdown editors can be resized by dragging their bottom edge, as the query editor already could.
A text cell shows its Markdown source with the markers highlighted while it is being edited, and the rendered result once editing finishes. Raw HTML is escaped and link targets are restricted to
http,https,mailtoand relative URLs.Implementation
The query text, parameters and result snapshot moved from the tab to a cell.
tab.query/tab.result/tab.resultEland the rest are now accessors onto the cell the editor is docked in, so the editor, history, URL and persistence code is unchanged and always means "the cell in front of the user". A run captures its own cell, so moving on to another cell mid-run does not redirect the response. The Logs/Metrics view and the resource meters follow the cell whose result they describe. The whole notebook is persisted in IndexedDB alongside the rest of the workspace, and history entries record the cell they belong to so Back/Forward cannot push one cell's query into another.A tab holding a single cell renders exactly as before — verified by screenshot diff against
master: 51 pixels differ, all on one row, all by 1 in a single channel.Testing
Driven in headless Chrome against a local server: cell creation and deletion, moving and inserting cells, collapsing and expanding, per-tab independence, tab duplicate/close with a docked editor, query parameters inside a cell, per-cell errors, reload restore from IndexedDB, "Run all" inside a cell, the Logs and Metrics views per cell, column and result resizing, the theme switch and download menu inside the docked Run row, Markdown rendering and backdrop alignment, and light and dark themes.
Two pre-existing issues were fixed along the way: the download drop-down positioned itself without accounting for
#main's scroll offset, and the#runsubmit button neededform="controls"once it could be moved out of the form's subtree.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added a notebook mode to the Web UI (
/play). After a query is run, a[+]button under the result adds further cells, each either a query with its own result or a block of Markdown text, turning the tab into a notebook in the style of Jupyter or Observable. Cells can be run, reordered, inserted and deleted individually; the query editor collapses to a single line when it is not focused, results are bounded and scroll inside themselves, and the whole notebook is restored on reload. Notebook mode is per tab, so a tab that has only one cell looks and behaves exactly as before.Workflow [PR]
Sync PR [sync-upstream/pr/115378]
Version info
26.10.1.1348-master(included in26.10and later)