fix(editor): frontmatter is unreachable; presets keep the card on phones #982

Closed
kayg wants to merge 0 commits from fix/frontmatter-unreachable into dev
Owner

What broke (prod ad1b89e2, kayg 11-06)

1. Backspace reached the hidden frontmatter (data corruption).
The default mode hides the properties block with one block-replace decoration over 0 … closing fence and marks it atomic. Atomic ranges only steer the caret; they never stop an edit. The block's last line break sits one character before the body, outside the replaced range. So at the body's first position CodeMirror's Backspace (deleteCharBackward, the default keymap in editor.ts) deletes exactly that line break; the closing --- joins the next line (or ends the document with no break). The editor reads a block only if its closing line ends with a line break, so the block stops being a block and all of it shows as ordinary text, one property per paragraph; the next Backspaces eat the closing fence. The save wrote it (the server tolerated a closing fence with no line break).
Reproduced on dev before this PR: Backspace x20 at the start of an empty body leaves the editor with no properties block at all.
Style writing frontmatter does not shift the caret into the block (the change sits before the caret and maps it forward). The other open door was a caret at position 0 in a freshly opened note (a new state starts there, inside the hidden block).

2. A preset made the card smaller on a phone — not reproduced as a change; the cause is the stored width.
Per frame, in Chromium and WebKit on a touch phone (390), for Wide, Narrow and a daily note with a leftover calternal-width: wide: a preset changes nothing about the page or card boxes. What is smaller is the stored Wide itself. Width is not offered on a phone (#395: "the page is always the screen's width"), but the page still draws a stored Narrow/Wide as a floating card that hugs its text: page 0,0,390,844, card 10,56,370,273.7 for a short note, against 10,56,370,778 (the screen's own card) for a note with no width. #967 keeps existing values, so a width left by an old look stays, and cannot be changed or removed on the phone.
I first fixed it by making the phone ignore a stored width, then reverted that: 6 existing specs (width.spec.ts, opacity.spec.ts at 390) assert floating Narrow/Wide cards on phones, so that behaviour looks intended, and changing it is a design call, not mine. Decision for kayg, options: (A) a phone ignores a stored width (the one-commit change is 437ba5193 in this PR's history, reverted by f02917fa4; the 6 specs would need rewriting); (B) show the Width row on a phone when the note has a stored Narrow/Wide, so it can be cleared; (C) leave it. The regression spec style-card-box.spec.ts passes on dev and here, and stays.

The fix (bug 1)

Editor (packages/editor/src/syntax/hidden.ts, the existing prefix filter) — for everything except the shared document's own changes and the properties writer (user event input.properties):

  • a change that starts inside the block refuses the whole transaction (Backspace at the body's start, a letter at position 0, a composition);
  • no selection end is inside the block (select all selects the body; typing, copy and cut never include a property); a new state's caret starts in the body (editor.ts), and a mode switch re-checks it (mode.ts);
  • the only way in is the writer: setStyleKeys / setTags (Style, cover, tags) dispatch with userEvent: "input.properties";
  • changes from the shared document (other devices, server keys, undo) are never refused.
    Source mode installs none of this.

Server save boundary (crates/notes/src/frontmatter_guard.rs, room/save.rs) — each save is judged against the block the last save wrote: a lost closing line break is put back as one small edit; properties still in the text but no longer in a block refuse the save (NotSavedYet) and the file keeps its previous properties; properties deleted wholesale are fine. Covers older tabs, other apps and agents.

Known gate miss (first paint)

first_js_brotli is +0.04 KB over dev (225.434 vs 225.395; raw +0.33 KB, gzip +0.11 KB). The guard is ~300 raw bytes in the first-paint chunk; brotli moves +-0.04 KB with any change of content, so micro-trimming did not get it under dev. Budget (240) is fine. Needs an orchestrator call (offset elsewhere, or accept).

Tests (failing first; runs are in the comments)

  • e2e/frontmatter-unreachable.spec.ts: Backspace x20 after a Style preset change (body and empty body), Delete x20 from the end of the title, select all + Backspace, paste over everything, cut, arrows/Home/PageUp then typing, a fresh note (caret at 0), direct dispatches of every kind refused, the writer still works, composition (Chromium via CDP; WebKit cannot drive an input method).
  • e2e/style-card-box.spec.ts: every look keeps the page, card and text-column boxes in every frame on a touch phone and at 1440 (wide, narrow, daily note with a leftover width).
  • packages/editor/test/frontmatter-unreachable.test.ts: the filter on a real view.
  • crates/notes: frontmatter_guard unit tests and a_save_never_turns_the_properties_into_body_text.

No open PR covers this.

🤖 Generated with Claude Code

## What broke (prod `ad1b89e2`, kayg 11-06) **1. Backspace reached the hidden frontmatter (data corruption).** The default mode hides the properties block with one block-replace decoration over `0 … closing fence` and marks it atomic. Atomic ranges only steer the **caret**; they never stop an **edit**. The block's last line break sits one character *before* the body, outside the replaced range. So at the body's first position CodeMirror's Backspace (`deleteCharBackward`, the default keymap in `editor.ts`) deletes exactly that line break; the closing `---` joins the next line (or ends the document with no break). The editor reads a block only if its closing line ends with a line break, so the block stops being a block and all of it shows as ordinary text, one property per paragraph; the next Backspaces eat the closing fence. The save wrote it (the server tolerated a closing fence with no line break). Reproduced on dev before this PR: Backspace x20 at the start of an empty body leaves the editor with no properties block at all. Style writing frontmatter does not shift the caret into the block (the change sits before the caret and maps it forward). The other open door was a caret at position 0 in a freshly opened note (a new state starts there, inside the hidden block). **2. A preset made the card smaller on a phone — not reproduced as a change; the cause is the stored width.** Per frame, in Chromium and WebKit on a touch phone (390), for Wide, Narrow and a daily note with a leftover `calternal-width: wide`: a preset changes **nothing** about the page or card boxes. What is smaller is the stored Wide itself. Width is not offered on a phone (#395: "the page is always the screen's width"), but the page still draws a stored Narrow/Wide as a **floating card that hugs its text**: page `0,0,390,844`, card `10,56,370,273.7` for a short note, against `10,56,370,778` (the screen's own card) for a note with no width. #967 keeps existing values, so a width left by an old look stays, and cannot be changed or removed on the phone. I first fixed it by making the phone ignore a stored width, then **reverted that**: 6 existing specs (`width.spec.ts`, `opacity.spec.ts` at 390) assert floating Narrow/Wide cards on phones, so that behaviour looks intended, and changing it is a design call, not mine. **Decision for kayg**, options: (A) a phone ignores a stored width (the one-commit change is `437ba5193` in this PR's history, reverted by `f02917fa4`; the 6 specs would need rewriting); (B) show the Width row on a phone when the note has a stored Narrow/Wide, so it can be cleared; (C) leave it. The regression spec `style-card-box.spec.ts` passes on dev and here, and stays. ## The fix (bug 1) **Editor (`packages/editor/src/syntax/hidden.ts`, the existing prefix filter)** — for everything except the shared document's own changes and the properties writer (user event `input.properties`): - a change that starts inside the block refuses the whole transaction (Backspace at the body's start, a letter at position 0, a composition); - no selection end is inside the block (select all selects the body; typing, copy and cut never include a property); a new state's caret starts in the body (`editor.ts`), and a mode switch re-checks it (`mode.ts`); - the only way in is the writer: `setStyleKeys` / `setTags` (Style, cover, tags) dispatch with `userEvent: "input.properties"`; - changes from the shared document (other devices, server keys, undo) are never refused. Source mode installs none of this. **Server save boundary (`crates/notes/src/frontmatter_guard.rs`, `room/save.rs`)** — each save is judged against the block the last save wrote: a lost closing line break is put back as one small edit; properties still in the text but no longer in a block refuse the save (`NotSavedYet`) and the file keeps its previous properties; properties deleted wholesale are fine. Covers older tabs, other apps and agents. ## Known gate miss (first paint) `first_js_brotli` is **+0.04 KB** over dev (225.434 vs 225.395; raw +0.33 KB, gzip +0.11 KB). The guard is ~300 raw bytes in the first-paint chunk; brotli moves +-0.04 KB with any change of content, so micro-trimming did not get it under dev. Budget (240) is fine. Needs an orchestrator call (offset elsewhere, or accept). ## Tests (failing first; runs are in the comments) - `e2e/frontmatter-unreachable.spec.ts`: Backspace x20 after a Style preset change (body and empty body), Delete x20 from the end of the title, select all + Backspace, paste over everything, cut, arrows/Home/PageUp then typing, a fresh note (caret at 0), direct dispatches of every kind refused, the writer still works, composition (Chromium via CDP; WebKit cannot drive an input method). - `e2e/style-card-box.spec.ts`: every look keeps the page, card and text-column boxes in every frame on a touch phone and at 1440 (wide, narrow, daily note with a leftover width). - `packages/editor/test/frontmatter-unreachable.test.ts`: the filter on a real view. - `crates/notes`: `frontmatter_guard` unit tests and `a_save_never_turns_the_properties_into_body_text`. No open PR covers this. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
kayg added 15 commits 2026-11-06 07:03:45 +00:00
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A lost closing line break is put back as one small edit; a block that would be unwrapped
refuses the save and the file keeps its previous properties.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(editor): a phone's page ignores a stored Narrow or Wide (presets keep the card)
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled
437ba5193b
Width is not offered on a phone (#395), but the page still drew a short floating card for a
stored Narrow or Wide, so a note with a width left from before #967 showed a smaller card than
any other note. The phone's page is now the screen's own card whatever the file says.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
Owner

Gate results (head f1b0a092)

Failing first (specs from this PR run against origin/dev 7a9bd54e, Chromium 390 on dev-01): 8 of the 11 cases fail (the 3 that pass are the fresh-note case, the writer case and the composition case); e.g. Backspace x20 at an empty body: expected the 10-line properties block, received "" (no block left). style-card-box is not a failing-first spec (it passes on dev: presets do not move the card).

On this branch

  • Playwright, final head, dev-02 (aarch64): Chromium 390+1440 197 passed, 0 failed; WebKit 390+1440 195 passed, 0 failed (frontmatter-unreachable, style-card-box, editor, enter, tags, cover, backdrops, style-sheet, style-presets, fresh-note, note-bars, day, width, vim, opacity, trash-search). Skipped: project-specific skips (composition on WebKit: no input-method driver).
  • Earlier, dev-01 (x86_64) Chromium 390+1440 of the two new specs: 28 passed. dev-01's /tmp has run out of inodes since ~08:10 CEST (1,048,576 used, df shows 59% bytes): leaked nix-shell.* dirs (~3000) and cargo/test targets of other jobs; I did not delete other jobs' files. Later runs moved to dev-02.
  • Editor unit 526 passed; web unit 109 passed; tsc --noEmit clean; svelte-check 0 errors (16 existing warnings). cargo test -p calternal-notes (frontmatter_guard x5, a_save_never_turns_the_properties_into_body_text, saved_bytes_and_titles_match_the_old_copy_path) passed; clippy --all-targets -D warnings clean; cargo fmt applied.
  • perf/web.sh --bundle-only --gate: all gated budgets ok. first_js_brotli 225.434 KB vs dev 225.395 (+0.04 KB, a miss against "first paint <= dev", see PR body); gzip 265.036 vs 264.922; raw 793.884 vs 793.557.
  • Typing latency (editor.spec.ts "keystroke to paint", Chromium 1440, dev-02, not dev-01; ABAB x4, default mode, p50/p95 ms): dev 34.6/94.2, 39.0/111.4, 37.5/111.1, 37.6/112.6 vs branch 39.1/110.5, 35.9/89.0, 38.1/108.2, 38.3/90.8. Means p50 37.2 vs 37.9, p95 107 vs 99.6: flat within the run-to-run spread. (That host fails the spec's own p95 < 50 gate on both builds; it has no GPU.) Source mode: same shape. Measured before the filter was merged into the prefix filter; the final filter does less per keystroke (no extra pass), but I did not re-run latency on the final head.
  • Safari frames: pending: Mac VM paused.

Recovery for kayg's damaged note (prod untouched): see the final report.

## Gate results (head `f1b0a092`) **Failing first** (specs from this PR run against `origin/dev` `7a9bd54e`, Chromium 390 on dev-01): 8 of the 11 cases fail (the 3 that pass are the fresh-note case, the writer case and the composition case); e.g. Backspace x20 at an empty body: expected the 10-line properties block, received `""` (no block left). `style-card-box` is not a failing-first spec (it passes on dev: presets do not move the card). **On this branch** - Playwright, final head, dev-02 (aarch64): Chromium 390+1440 **197 passed, 0 failed**; WebKit 390+1440 **195 passed, 0 failed** (frontmatter-unreachable, style-card-box, editor, enter, tags, cover, backdrops, style-sheet, style-presets, fresh-note, note-bars, day, width, vim, opacity, trash-search). Skipped: project-specific skips (composition on WebKit: no input-method driver). - Earlier, dev-01 (x86_64) Chromium 390+1440 of the two new specs: 28 passed. dev-01's `/tmp` has run out of **inodes** since ~08:10 CEST (1,048,576 used, df shows 59% bytes): leaked `nix-shell.*` dirs (~3000) and cargo/test targets of other jobs; I did not delete other jobs' files. Later runs moved to dev-02. - Editor unit 526 passed; web unit 109 passed; `tsc --noEmit` clean; `svelte-check` 0 errors (16 existing warnings). `cargo test -p calternal-notes` (frontmatter_guard x5, `a_save_never_turns_the_properties_into_body_text`, `saved_bytes_and_titles_match_the_old_copy_path`) passed; `clippy --all-targets -D warnings` clean; `cargo fmt` applied. - `perf/web.sh --bundle-only --gate`: all gated budgets ok. `first_js_brotli` 225.434 KB vs dev 225.395 (**+0.04 KB, a miss against "first paint <= dev"**, see PR body); gzip 265.036 vs 264.922; raw 793.884 vs 793.557. - Typing latency (`editor.spec.ts` "keystroke to paint", Chromium 1440, **dev-02, not dev-01**; ABAB x4, default mode, p50/p95 ms): dev 34.6/94.2, 39.0/111.4, 37.5/111.1, 37.6/112.6 vs branch 39.1/110.5, 35.9/89.0, 38.1/108.2, 38.3/90.8. Means p50 37.2 vs 37.9, p95 107 vs 99.6: flat within the run-to-run spread. (That host fails the spec's own p95 < 50 gate on both builds; it has no GPU.) Source mode: same shape. Measured before the filter was merged into the prefix filter; the final filter does less per keystroke (no extra pass), but I did not re-run latency on the final head. - Safari frames: **pending: Mac VM paused**. **Recovery for kayg's damaged note (prod untouched):** see the final report.
Author
Owner

Closing: already in dev (merged as #982 into dev, and hotfixed to prod via #983 / release/2026-11-06-hotfix). Head f1b0a092f74a4591e4ae1903450a378223c8b7cf; reopen if needed. (Housekeeping 2026-11-09 night)

Closing: already in dev (merged as #982 into dev, and hotfixed to prod via #983 / release/2026-11-06-hotfix). Head `f1b0a092f74a4591e4ae1903450a378223c8b7cf`; reopen if needed. (Housekeeping 2026-11-09 night)
kayg closed this pull request 2026-11-09 18:46:29 +00:00
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!982
No description provided.