Skip to content

docs: document breakableFitAdvances cache invariant#139

Open
shaun0927 wants to merge 1 commit intochenglou:mainfrom
shaun0927:fix/document-breakable-fit-cache-invariant
Open

docs: document breakableFitAdvances cache invariant#139
shaun0927 wants to merge 1 commit intochenglou:mainfrom
shaun0927:fix/document-breakable-fit-cache-invariant

Conversation

@shaun0927
Copy link
Copy Markdown

Fixes #137

Problem

getSegmentBreakableFitAdvances() accepts a mode: BreakableFitMode parameter but the cache at line 203 returns the stored result without checking whether the mode matches. If a future caller requested the same segment text with a different mode, the cache would silently return the wrong advances.

Why the cache is safe today

The mode is fully determined by two things that are constant for a given segment text within a session:

  1. isNumericRunSegment(text) — pure text predicate, always returns the same result for the same string → forces pair-context
  2. engineProfile.preferPrefixWidthsForBreakableRuns — detected once from navigator.userAgent, invariant for the session → forces segment-prefixes
  3. Otherwise → sum-graphemes

So the same segment text always arrives with the same mode, and the mode-agnostic cache never returns a mismatched result.

Change

Added a 5-line comment above the cache check explaining the invariant and the consequence of breaking it. No behavior change, no public API change. All 84 tests pass.

Test plan

  • bun test src/layout.test.ts — 84 pass, 0 fail
  • Comment-only change — no runtime effect

The cache check in getSegmentBreakableFitAdvances returns the stored
result without consulting the mode parameter. This is safe because
the current call sites guarantee mode is determined by
isNumericRunSegment (text-deterministic) and the session-invariant
engine profile, so the same segment text always arrives with the
same mode.

Add a comment explaining this invariant so future callers know
the constraint. No behavior change.
aculich added a commit to aculich/pretext that referenced this pull request Apr 21, 2026
Log pretext-upstream-rhythm session in WORKFLOW (merge f201433, checks, triage wave chenglou#139/chenglou#132, fork scan).

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getSegmentBreakableFitAdvances: cached result does not distinguish BreakableFitMode

1 participant