Repository navigation
fix(lynx): gate first-screen event emission on resolved visibility (#81) - #97
Merged
Merged
Conversation
The background announces a first-screen listener only for a host it resolves as visible (`universal-core.ts`, `isVisible &&`). The main renderer walked every host with `visitHosts` and no gate, marking hidden subtrees afterwards with trailing `visibility` commands. So a `bind*`/`catch*` handler anywhere inside a hidden `<Activity>` made the two batches disagree by exactly one `event` command. A first screen whose event bindings do not match the background's can never be adopted. The consequence on every launch of such a page is that the paint is thrown away and rebuilt, native node identity with it, and any tap made before the background caught up is silently discarded — strictly worse than having no synchronous first screen at all. A hidden tab, a collapsed drawer, and a pre-rendered off-screen route are all this shape. Reported as #81; pre-existing, not stack drift. The renderer now walks with the same inherited-visibility rule the host driver applies — a host is visible when it is not itself hidden and no host above it is. Hidden hosts are still created and still receive their props; only what they announce is gated. That rule is also what the direct applier already used when *installing* events, so the batch was the half that disagreed. Pinned twice. At the batch level the main and background batches must be equal for that shape, using the comparison helper this suite already had, with a visible control proving the gate is not over-broad. End to end, the retained integration's adoption round now carries a handler on its hidden Activity and asserts no mismatch diagnostic; without the gate it reports "Octane Lynx first-screen mismatch at snapshot.nodes[13].events: the event binding count differs", deterministically across runs. The visible control deliberately does not compare against the background batch: the background seeds listener IDs from a per-process root counter while the first-screen renderer always starts at 1_000_000, so the two agree only for the first root built in a process. That is production's arrangement but not a suite's, and pinning it would pin the suite's ordering. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Huxpro
changed the base branch from
test/lynx-target-first-screen-coverage
to
new-lynx
August 19, 2026 18:37
Huxpro
marked this pull request as ready for review
August 19, 2026 18:37
This was referenced Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The background announces a first-screen listener only for a host it resolves as
visible (
universal-core.ts,isVisible &&). The main renderer walked everyhost with
visitHostsand no gate, marking hidden subtrees afterwards withtrailing
visibilitycommands.So a
bind*/catch*handler anywhere inside a hidden<Activity>made the twofirst-screen batches disagree by exactly one
eventcommand. Reported as #81 —pre-existing, not stack drift.
Why this is worse than a cosmetic mismatch
A first screen whose event bindings do not match the background's can never be
adopted. On every launch of such a page:
The synchronous first screen exists to make the first paint fast and
interactive. For this class of page it was strictly worse than not having one:
the user pays for the paint, then pays for a full rebuild. A hidden tab, a
collapsed drawer, and a pre-rendered off-screen route are all this shape.
Changes
packages/lynx/src/main-renderer.ts: the event pass walks withvisitHostsWithVisibility, using the same inherited rule the host driverapplies — a host is visible when it is not itself hidden and no host above it
is. Hidden hosts are still created and still receive their props; only what
they announce is gated.
That rule is also what
applyLynxFirstScreenDirectalready used wheninstalling events (
if (visible && hostEvents !== undefined)). The applierwas already right; the batch was the half that disagreed with both it and the
background.
Validation
Pinned at two levels, because "the batches agree" and "the page adopts" are
different claims.
Batch level (
main-renderer.test.ts) — using the main-vs-backgroundcomparison helper this suite already had:
<Activity>:main.batchmust equal the backgroundbatch, and emit no
eventcommand, with a guard that the fixture really doeshide a host so the assertion is not vacuous;
listener — the gate is not over-broad.
The visible control deliberately does not compare whole batches. The
background seeds listener IDs from a per-process root counter
(
NEXT_EVENT_ROOT++ * 1_000_000) while the first-screen renderer always startsat
1_000_000, so the two agree only for the first root built in a process —production's arrangement, but not a suite's. Comparing them there would pin the
suite's own ordering. I hit this as a spurious
3000000vs1000000diff andchased it before concluding it was not a second defect; the comment in the test
says so, so the next reader does not repeat it.
End to end (
milestone-8-integration.test.ts) — the retained-integrationadoption round already covered hidden Activity nodes through the vendored
@lynx-js/testing-environmentDOM, but without a handler on them. It now carriesone, and asserts no mismatch diagnostic before the identity comparisons, because
a mismatch rebuilds the tree and those comparisons would then fail for the wrong
reason.
Red-green, removing the gate — deterministic, 3 runs each way:
Octane Lynx first-screen mismatch at snapshot.nodes[13].events: the event binding count differs— 1 failed / 2 passed, 3/3 runslynxproject 372 passedThat is #81's reported diagnostic, reproduced from the public API rather than
asserted from the inside.
pnpm typecheckpnpm sync(no generated changes)pnpm format:fileson every changed pathpnpm vitest run --project lynx --project octane --project octane-prod --project rspeedy-plugin— 12,871 passed, 1 failed: thenative-demo"escalates cleanup for a detached descendant" case issue Execution plan (#58): complete L2, then drive L4→L6 — full context handoff #66 §2 already
names as pre-existing here, and which reproduces on the base commit
pnpm testrepo-wide (run at perf(lynx): classify host updates without building the prop patch (issue-66 A4) #92 and perf(compiler): name lynx create-function locals by depth (#86) #95)Measurement
Not measured, deliberately, and not claimed. The change only removes
commands from the first-screen batch, and it fires only for hidden hosts
carrying handlers.
benchmarks/lynx-tablehas no<Activity>at all, so anFCP@10k A/B would compare a build against itself — a no-op dressed as evidence.
The pages this helps are the ones that previously could not adopt, where the win
is a whole rebuild rather than milliseconds, and this container cannot drive
that end of it.
Risk / follow-ups
visitHostsWithVisibilityis recursive, like thevisitHosts,physicalChildren,stagePlacements, andcollectHiddenPostOrderwalks itsits beside. It adds no depth ceiling those did not already impose — the
renderer's own recursion is what bounds this side, and applyLynxFirstScreenDirect recurses per host level, so deep first screens now hard-fail with RangeError — and a throw has no staged fallback #90 measured it deeper
than the applier's was.
mismatch into silent input loss. That is untouched here. This PR removes the
mismatch that triggers it, which should make it unreachable for this shape,
but it does not fix the truncation itself.
<Activity>failingtsrx-tscwith TS2604)currently masks A first screen can never be adopted if any host inside a hidden <Activity> carries a bind*/catch* handler #81, and that fixing the typing first would turn a feature
that "doesn't typecheck" into one that typechecks and then discards the first
screen. Landing A first screen can never be adopted if any host inside a hidden <Activity> carries a bind*/catch* handler #81 first is the safe order; <Activity> fails tsrx-tsc with TS2604 everywhere, including committed fixtures in published packages #91 is still open and is
orthogonal to this stack.
Provenance
agent-authored)Generated by Claude Code