Skip to content

fix(lynx): gate first-screen event emission on resolved visibility (#81) - #97

Merged
Huxpro merged 1 commit into
new-lynxfrom
fix/lynx-hidden-activity-events
Aug 19, 2026
Merged

Huxpro merged 1 commit into
new-lynxfrom
fix/lynx-hidden-activity-events

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Summary

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
first-screen batches disagree by exactly one event command. 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 paint is thrown away and rebuilt;
  • native node identity goes with it — every painted node destroyed and recreated;
  • any tap made before the background caught up is silently discarded.

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 with
    visitHostsWithVisibility, using the same inherited 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 applyLynxFirstScreenDirect already used when
installing events (if (visible && hostEvents !== undefined)). The applier
was 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-background
comparison helper this suite already had:

  • a handler inside a hidden <Activity>: main.batch must equal the background
    batch, and emit no event command, with a guard that the fixture really does
    hide a host so the assertion is not vacuous;
  • a visible control: the same handler, shown, still announces exactly one
    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 starts
at 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 3000000 vs 1000000 diff and
chased 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-integration
adoption round already covered hidden Activity nodes through the vendored
@lynx-js/testing-environment DOM, but without a handler on them. It now carries
one, 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:

state result
gate removed Octane Lynx first-screen mismatch at snapshot.nodes[13].events: the event binding count differs — 1 failed / 2 passed, 3/3 runs
gate restored 3 passed, 3/3 runs; whole lynx project 372 passed

That is #81's reported diagnostic, reproduced from the public API rather than
asserted from the inside.

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-table has no <Activity> at all, so an
FCP@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

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant