Skip to content

fix(render): a streamed soft visit holds to the page on screen - #1358

Merged
sebyx07 merged 8 commits into
mainfrom
fix/soft-stream-review
Nov 24, 2026
Merged

sebyx07 merged 8 commits into
mainfrom
fix/soft-stream-review

Conversation

@sebyx07

@sebyx07 sebyx07 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the review threads left open on #1319.

Fixed

Thread Change
newer swap during script loading after the shell's scripts and ultimate:navigated, the swap checks it still owns the tab before filling; otherwise the unread answer is cancelled
stop() from a navigated listener same check; stop() also aborts the answer still being read. e2e: the stopped router cancels the request and fills nothing
stream fails while the next visit is fetching recovery is held until that navigation settles and runs only if it never took the tab; every path where the router hands the tab to the browser drops it
fragment URL recovery is not a reload loadForReal: a URL that differs from the page on screen only by its fragment is reloaded. Used by the broken-stream GET recovery, the failed-swap GET recovery and ultimate:navigation-error's default
cancellation wording, same in the wiki changelog, wiki and comment: cancel aborts each hole's signal; a read that passes it on stops, one that ignores it runs to its end and is dropped
observe the hole's own signal the cancellation e2e asserts the held read's signal is aborted before the hole is released
navigated may move to stream end e2e listener asserts ultimate:navigated carries the URL while the hole is still held
body error after the swap new ?break fixture: a GET is loaded for real (with a fragment: reloaded), a POST raises ultimate:navigation-error and is sent once
byte-split UTF-8 shell and chunk encoded once, split inside 2-, 3- and 4-byte characters
keep-alive frames retained whole keep-alive frames at the head of the buffer are dropped as they arrive. STREAM_KEEPALIVE_CHUNK now lives beside the flush mark in stream-scripts.ts and is re-exported from render-stream.ts
fragment inside a hole lateFragment: retried after each chunk until the element exists, unless the visitor scrolled or changed the hash; never on Back/Forward
reused prefetch waits stated in Client-Navigation, Routes-And-Render-Modes and Known-Gaps
navigated event row the Events row says hole scripts run later

Not changed

  • flush mark inside JSON: no rendered value can spell <!--x:flush-->. Text and attributes go through escapeHtml, script and style bodies through escapeRawTextContent (<!-- → <\!--), JSON blocks through escapeJsonContent (< → \u003c). Only an author's own innerHTML emits raw markup, and that is already full HTML control. A new test pins the property for all three escapers.

Size

Router 31,904 → 32,620 B minified (+716 B), 11,507 → 11,765 B gzip, stated in wiki/Client-Navigation.md and the changelog. Six examples/dummy route budgets raised to their measured totals (x build --target static), each with a measured: comment. budget-raises and the budgets step pass.

Checks run

bun test on navigation-stream, navigation, render-stream (57 pass) and the stream-hole e2e in Chrome (10 pass). The new e2e cases and the fragment unit test were red before the fix. tsc -b packages/render is clean. No full local verify; CI is the gate.

🤖 Generated with Claude Code

@developerz-ai

developerz-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Reviewed (latest push only: 1 commit(s) since 8eb62da, not the full PR)

2 actionable comment(s) · grounded on your code

@developerz-ai developerz-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Commented. This review is not an approval.

Review summary: 22 file(s), 16 finding(s).

Critical 0 · Major 1 · Minor 14 · Nit 1

The PR changes streamed navigation cancellation, recovery and fragment scrolling. A newer visit that never swaps can strand the visible shell, and a late stream failure can override a pending browser load. The PR changes streamed navigation recovery and late fragment scrolling.

File Findings
packages/cli/e2e/stream-hole-fixture.ts 1 minor
packages/cli/e2e/stream-hole-recovery.e2e.test.ts 2 minor
packages/cli/e2e/stream-hole.e2e.test.ts 3 minor
packages/render/src/navigation-history.ts 1 minor
packages/render/src/navigation-stream.test.ts 3 minor
packages/render/src/navigation-stream.ts 2 minor
packages/render/src/navigation.ts 1 major, 1 minor, 1 nit
wiki/Client-Navigation.md 1 minor

Reviewed with gpt-6.2-sol

Comment thread packages/render/src/navigation.ts Resolved
Comment thread packages/cli/e2e/stream-hole-fixture.ts Resolved
Comment thread packages/render/src/navigation.ts Resolved
Comment thread wiki/Client-Navigation.md Resolved
Comment thread packages/render/src/navigation.ts Resolved
@sebyx07
sebyx07 force-pushed the fix/soft-stream-review branch from 9909b47 to 523acee Compare November 24, 2026 10:13

@developerz-ai developerz-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Commented. This review is not an approval.

Review summary: 24 file(s), 10 finding(s).

Critical 0 · Major 1 · Minor 9 · Nit 0

The PR updates cancellation, recovery and fragment scrolling for streamed soft visits. A newer visit can still strand the visible shell, a stale failure can interrupt the newer page, and fragment recovery can reload a native POST entry.

File Findings
packages/cli/e2e/stream-hole-recovery.e2e.test.ts 2 minor
packages/render/src/navigation-history.ts 2 minor
packages/render/src/navigation-stream-recovery.test.ts 1 minor
packages/render/src/navigation.ts 1 major, 2 minor
wiki/Client-Navigation.md 1 minor
8 non-blocking finding(s) below major (no thread on a re-review, only blocking findings open threads)
  • packages/cli/e2e/stream-hole-recovery.e2e.test.ts:55 minor · test The fragment test passes if lateFragment ignores visitor scroll and hash changes, because neither changes before the hole is released. Add cases that scroll or change the hash while the hole is held, then assert the reveal does not jump to the old target.
  • packages/cli/e2e/stream-hole-recovery.e2e.test.ts:130 minor · test If the /before?hold request reaches the server after the 300 ms sleep, wire.release() calls the old resolver and the healthy router never receives its answer. Have the fixture signal when serve installs the current resolver, and await that signal before breaking the stream.
  • packages/render/src/navigation-history.ts:89 minor · bug If a soft swap to /page#new throws before recording history while /page#old is current, loadForReal reloads #old and never reaches the requested fragment. Preserve the requested fragment before forcing the document load.
  • packages/render/src/navigation-history.ts:109 minor · bug A visitor who scrolls away and back before the hole arrives matches the saved coordinates again and is pulled to the late fragment. Latch cancellation on the first scroll away from the landing position or hash change and clean up the listeners when filling ends.
  • packages/render/src/navigation-stream-recovery.test.ts:33 minor · test breakIt() sends a complete frame and relies on the fake DOM parser to reject it, so the deferred recovery cases still pass if rest.next() starts swallowing reader errors. Have breakIt() error the stream controller so the tests exercise the body-read rejection.
  • packages/render/src/navigation.ts:416 minor · bug If a modal opens over a fragmentless streamed page while its recovery is deferred, recover() loads the original fragmentless URL and closes the newly opened modal. When the current URL still names the streamed document, recover at that URL so the modal or a newer fragment survives.
  • packages/render/src/navigation.ts:482 minor · docs The comment promises no mutations after stop(), but stopping while shell scripts are pending still lets landFocus, ultimate:navigated and reconcile() run at lines 366-368 before the abort check. Limit the comment to the cancellation behavior this line guarantees.
  • wiki/Client-Navigation.md:512 minor · docs The event row says ultimate:navigated fires after scrolling, but for a fragment inside a pending hole the final scroll happens after that event. Say the event follows the initial scroll, not a late fragment scroll.
1 finding(s) outside this pull request's change (reported, not holding the merge)
  • packages/render/src/navigation-stream.ts:60 minor · performance When a read ends with a complete hole chunk followed by keep-alives, the saved suffix retains those comments until another read resolves, which can be much later for a hole with no deadline. Strip leading keep-alives from the suffix before returning the chunk.

These sit on code this pull request did not change, so they do not hold the merge.

Reviewed with gpt-6.2-sol

Comment thread packages/render/src/navigation.ts Resolved
@sebyx07
sebyx07 force-pushed the fix/soft-stream-review branch from 523acee to 7a7a35b Compare November 24, 2026 11:32

@developerz-ai developerz-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Commented. This review is not an approval.

Review summary: 24 file(s), 10 finding(s).

Critical 0 · Major 1 · Minor 9 · Nit 0

The PR changes streamed navigation recovery, cancellation, and fragment scrolling. The router can discard holes from the page still on screen, start a modal fetch after stop(), or reload the wrong fragment. The PR adds recovery, cancellation and late fragment scrolling for streamed visits.

File Findings
CHANGELOG.md 1 minor
packages/cli/e2e/stream-hole-recovery.e2e.test.ts 2 minor
packages/render/src/navigation-history.ts 1 major, 1 minor
packages/render/src/navigation-stream-recovery.test.ts 2 minor
packages/render/src/navigation.ts 2 minor
wiki/Routes-And-Render-Modes.md 1 minor
9 non-blocking finding(s) below major (no thread on a re-review, only blocking findings open threads)
  • CHANGELOG.md:48 minor · docs This entry and wiki/Known-Gaps.md:171 say a newer navigation cancels the request, but a visit that starts after hole filling begins and returns an empty 204 leaves the old stream running. State that cancellation normally happens when the next page replaces the current one, not when its request st…
  • packages/cli/e2e/stream-hole-recovery.e2e.test.ts:56 minor · test The late-fragment test leaves scroll and hash unchanged, so it still passes if the router always jumps to the target and interrupts a visitor who already scrolled or changed the hash. Add held-hole cases that move the viewport or change the hash before release and verify the late target does not ta…
  • packages/cli/e2e/stream-hole-recovery.e2e.test.ts:130 minor · test If /before?hold reaches the fixture after the 300 ms window, wire.release() runs before the fixture installs its resolver and the test times out on a healthy router. Await a fixture signal that the held request arrived before breaking the old body or releasing the new one.
  • packages/render/src/navigation-history.ts:109 minor · bug If the visitor scrolls down and back to the starting offset before the first hole lands, the coordinate snapshot still matches and the late fragment jumps the page despite that interaction. Latch intervening scroll or hash changes while waiting and dispose the listeners when the wait ends.
  • packages/render/src/navigation-stream-recovery.test.ts:33 minor · test breakIt() enqueues markup the fake parser does not know instead of rejecting the body read, so these recovery tests can pass on a parse failure without exercising a rejected reader.read(). Error the stream controller directly while the held fetch is still pending.
  • packages/render/src/navigation-stream-recovery.test.ts:34 minor · test breakIt() enqueues markup instead of rejecting the pending read, so the deferred recovery tests can pass on a fake DOM failure even if the router mishandles a network body rejection. Error the stream controller directly.
  • packages/render/src/navigation.ts:372 minor · bug On Back to a streamed page with a modal hash, a listener can call stop() at ultimate:navigated, but reconcile() runs before this guard and starts a new modal request on the stopped router. Check for cancellation before reconciling the hash.
  • packages/render/src/navigation.ts:417 minor · bug If a visitor changes /streamed to /streamed#section while a hole is open, a later body failure loads the captured /streamed and drops the visitor's fragment. Recover the current history URL when it still names the same document, including a modal hash opened while the stream was pending.
  • wiki/Routes-And-Render-Modes.md:345 minor · docs The client-router row promises a shell swap as soon as it arrives but lists only the prefetch exception, so readers choosing a streamed route modal expect progressive paint even though navigate drains its holes before showing it. State that a streamed modal waits for the whole answer too.

Reviewed with gpt-6.2-sol

@sebyx07
sebyx07 force-pushed the fix/soft-stream-review branch from 95b87b1 to 02585b0 Compare November 24, 2026 12:43
sebyx07 and others added 7 commits November 24, 2026 07:53
- A newer navigation or `stop()` that lands while the shell's scripts run, an
  `ultimate:navigated` listener included, cancels the answer before any hole
  is filled; `stop()` also cancels the answer still being read.
- A stream that breaks while the next visit is on its way waits for it and
  recovers only if that visit never took the tab.
- A broken stream, and `ultimate:navigation-error`'s default, on a URL with a
  fragment reload the page: `assign` there only scrolled.
- A fragment inside a hole is scrolled to when the hole lands, unless the
  visitor moved first.
- Keep-alive frames are dropped as they arrive instead of held until the next
  chunk.

Tests: e2e cases for each of the above in Chrome, a hole's signal observed on
cancel, `ultimate:navigated` seen with the hole still open, a POST whose body
dies is reported and never re-sent, a byte-split UTF-8 read, and a pin that no
escaped value can spell the flush mark. Docs state that cancellation aborts the
hole's signal, that a reused prefetch waits for the whole answer, and when
`ultimate:navigated` fires on a stream page.

Router: 31,904 -> 32,620 B minified (+716 B), 11,507 -> 11,765 B gzip. Six
reference-app route budgets raised by their measured totals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`location.hash` is the URL fragment, compared to tell whether the visitor
moved before a hole brought the fragment's element.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lock waits but Chrome's

The recovery cases move to stream-hole-recovery.e2e.test.ts over a shared
stream-hole-fixture.ts, keeping each file under the line ceiling. The hole's
signal is awaited on its abort event; the two remaining waits watch Chrome for
a load that must not start and say so. The fragment comparison's pin states
why it is new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…om filling

Review round on this branch:
- the tab handed to the browser (a real load, the error event's default reload,
  a failed swap's reload, a non-download hand-over) cancels the page being
  left, so its stream breaking later cannot load it over the pending load
- a stop while a hole's scripts run ends the fill before the fragment scroll
- the late-fragment baseline is taken right after the swap's own scroll, before
  any script or listener moves the visitor
- `/a#` counts as a fragment URL for the reload
- keep-alives between two chunks of one read are dropped too
- `STREAM_FLUSH_MARK` is exported from `@ultimat3/render/server` for readers of
  a stream; the e2e fixture uses it

Tests: a fake-DOM suite for broken-stream recovery (nothing pending, a newer
visit that lands, one that stays, a load already handed over), multibyte cuts
in every character, keep-alives inside one read, the empty fragment, and e2e
assertions on the event, the abort reason and the recovered fragment.

Router: 31,904 -> 32,699 B minified (+795 B), 11,809 B gzip. Budgets re-measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…loads

Back to `/page#part` whose soft fetch fails handed the browser `location.assign` of the URL it
already showed: a same-document fragment navigation, so the page being left stayed on screen.
`loadInstead` now goes through `loadForReal`, which reloads when the target differs from the
address bar only by its fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aches it

`loadForReal('/a#new')` with `/a#old` in the address bar reloaded `/a#old`: the requested anchor
was never reached. A target that differs from the address bar only by its fragment, and is not it,
is now pushed first, as `assign` would, then reloaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s budget re-measured on main (router 31,904 → 32,727)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sebyx07
sebyx07 force-pushed the fix/soft-stream-review branch from 02585b0 to 8eb62da Compare November 24, 2026 12:56

@developerz-ai developerz-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Commented. This review is not an approval.

Review summary: 24 file(s), 10 finding(s).

Critical 0 · Major 1 · Minor 8 · Nit 1

The PR updates streamed navigation, fragment scrolling and recovery. A newer visit can strand the visible page’s holes, and a browser handoff can still be overridden by a stream that starts filling afterward. The PR changes streamed navigation recovery, cancellation, and fragment scrolling.

File Findings
CHANGELOG.md 1 minor
packages/cli/e2e/stream-hole-recovery.e2e.test.ts 2 minor
packages/render/src/navigation-history.ts 1 minor
packages/render/src/navigation-stream-recovery.test.ts 2 minor
packages/render/src/navigation-stream.ts 1 minor
packages/render/src/navigation.ts 1 major, 1 minor, 1 nit
9 non-blocking finding(s) below major (no thread on a re-review, only blocking findings open threads)
  • CHANGELOG.md:62 minor · docs The changelog and wiki/Client-Navigation.md:70-71 report 32,699 B (+795 B), but the budget notes under examples/dummy/apps/web/app/ report 32,727 B (+823 B) at feed/page.tsx:259-260, posts/board/page.tsx:119-120, posts/new/page.tsx:130-131, runs/health/page.tsx:74-75, runs/page.tsx:226-227 and sett…
  • packages/cli/e2e/stream-hole-recovery.e2e.test.ts:57 minor · test This case starts at scroll zero and never moves before releasing the hole, so it still passes if lateFragment ignores user scrolling and jumps to the target every time. Add a held-hole case that scrolls before release and asserts the offset is preserved after the target appears.
  • packages/cli/e2e/stream-hole-recovery.e2e.test.ts:130 minor · test If /before?hold reaches the fixture after the 300 ms sleep, wire.release() runs before that request installs its resolver and the test times out on a healthy router. Have the fixture signal when it installs the resolver and await that signal before breaking the stream.
  • packages/render/src/navigation-history.ts:111 minor · bug If the visitor scrolls down and back to the original offset while a hole is held, the snapshot still matches and the late fragment jumps the viewport despite the documented scroll opt-out. Latch scroll or hash changes while waiting and remove the listeners when filling ends or is cancelled.
  • packages/render/src/navigation-stream-recovery.test.ts:33 minor · test breakIt() delivers a complete frame and relies on the fake DOM parser to reject it, so the deferred recovery tests pass even if a rejected body read is swallowed. Error the stream controller while the next response is held so the tests exercise a rejected reader.read().
  • packages/render/src/navigation-stream-recovery.test.ts:34 minor · test breakIt() enqueues a marked chunk without rejecting the body, so these tests can pass on a fake DOM parsing failure even if reader rejection no longer triggers recovery. Call controller.error() after the shell lands to exercise the same failure as a dropped connection.
  • packages/render/src/navigation-stream.ts:55 minor · performance When one read ends with a complete hole chunk followed by a batch of keep-alives, restOf retains every trailing frame while scripts run or the next read waits. Apply withoutKeepAlives to the suffix at line 60 before returning the chunk.
  • packages/render/src/navigation.ts:370 minor · bug If an ultimate:navigated listener calls stop() on a page whose hash names a modal, reconcile() still runs before the abort check and can start a modal fetch on the stopped router. Check for abort immediately after dispatch, before reconciling the hash.
  • packages/render/src/navigation.ts:483 nit · docs The comment promises no mutation after stop(), but when an ultimate:navigated listener calls it, navigate() still reaches finally and removes data-x-navigating after stop() returns. Describe the narrower guarantee that stopping aborts pending navigation and hole filling.

Reviewed with gpt-6.2-sol

Comment thread packages/render/src/navigation.ts Resolved
@developerz-ai

developerz-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Needs a human: developerz-ai/ultimate #1358: no machine has picked up the fix for this change.

The fix round for this PR has waited in the queue far past the CI window and no machine has picked it up: either no box enrolled for this account is online and able to run it (the details name any capability or service it is missing), or every box that can is busy. Nothing moves the PR until one takes it. Bring a box online that can run this repository, free one up, or take the fix over by hand.

…T's unread holes

After a streamed POST answered for another principal, the tab is no longer trusted to swap, so a
GET an `ultimate:navigated` listener starts goes straight to the browser. That handoff never
aborted the POST's own visit: its unread holes started filling after the tab was handed over, and
a body that broke then reloaded the old page over the new destination. `loadInstead` now aborts the
visit in flight before handing over.

Router 32,727 → 32,738 B (+11): every dummy route re-measured; `/posts/board` raised 121.4kb →
121.5kb (124,319 B), the rest still fit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@developerz-ai developerz-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approved.

Review summary: 10 file(s), 2 finding(s).

Critical 0 · Major 0 · Minor 2 · Nit 0

The router now cancels unread POST content when a navigation listener hands the tab to the browser. The PR description understates the measured router growth. The new regression test verifies cancellation but does not check that an already buffered hole stays off screen.

2 non-blocking finding(s) below major (no thread on a re-review, only blocking findings open threads)
  • CHANGELOG.md:62 minor · docs The PR’s Size section understates the per-route minified cost by 118 B: it reports 32,620 B (+716 B), while the updated changelog and route budgets record 32,738 B (+834 B). Update the PR description to match the measurements at this commit.
  • packages/render/src/navigation-stream-recovery.test.ts:161 minor · test The fixture sends only the shell, and breakIt() does nothing after the test confirms cancellation, so the test passes even if the router processes buffered holes before cancelling. Queue a valid hole with the shell and assert that its content or script never lands when the listener hands off the…

Reviewed with gpt-6.2-sol

@sebyx07
sebyx07 merged commit 91aff19 into main Nov 24, 2026
43 checks passed
@sebyx07
sebyx07 deleted the fix/soft-stream-review branch November 24, 2026 13:50
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.

1 participant