Skip to content

test(Link): wait for the visibility observer instead of a fixed timeout - #543

Merged
IgorShevchik merged 1 commit into
mainfrom
sync/nuxt-8a25c22b
Sep 7, 2026
Merged

test(Link): wait for the visibility observer instead of a fixed timeout#543
IgorShevchik merged 1 commit into
mainfrom
sync/nuxt-8a25c22b

Conversation

@IgorShevchik

Copy link
Copy Markdown
Collaborator

Port of nuxt/ui@8a25c22b — third in the Link prefetch chain after c4ee0ea3 (#538) and 612ab1cb (#541), and a consequence of the second.

612ab1cb put the visibility observer behind onNuxtReady, so registration now runs through two deferrals instead of one. The spec still waited a flat 10 ms and then did a non-null instances[0]! on a value that might not be there yet. Upstream replaces that with a vi.waitFor-based waitForObserver() for the positive case, and lifts idle() to 50 ms for the two negative cases — which cannot poll for something meant never to appear.

Applies verbatim. test/components/nuxt/LinkPrefetch.spec.ts was byte-identical to upstream's pre-image, checked with a whole-file diff against 612ab1cb, not just at the hunks.

The measurement cuts against the commit subject

Instrumented the positive case with a 1 ms polling loop: registration completes in 2 ms, three runs of three. The old 10 ms had a 5× margin here and the suite was green on main after #541. So this guards a loaded CI runner rather than repairing a break — worth stating, because the subject reads like a fix.

It also corrects a reading of vi.waitFor: timing the helper itself reports 51 ms, which is its poll interval, not the registration time. The two differ by 25× and only the smaller one is about the code under test.

The real gain is an assertion, not a timeout

instances[0]! reads the first observer and ignores any others. waitForObserver asserts toHaveLength(1) — and observeIntersection shares one IntersectionObserver across every link, tearing it down once the last caller unobserves. "Exactly one" is the invariant that sharing holds, and nothing asserted it before.

Mutation-checked:

mutation on this branch on the pre-image
observeIntersection returns without observing 1 failed
a second IntersectionObserver per call (sharing broken) 1 failed 5 passed

The second row isolates the coverage this commit adds: the same mutation is invisible to the spec as it stood.

Bookkeeping

  • .sync/nuxt-ui.json — cursor 612ab1cb8a25c22b, entry added with the pending-merge placeholder per PORTING.md §6 step 4.
  • .sync/dep-parity.json — refreshed at the new cursor; the cursor line is the only change, since the commit touches no manifest.
  • .sync/log/8a25c22b….md — the long-form reasoning.

Local gate green: lint · typecheck · build (3.87 MB) · test (343 files, 7847 passed, 6 skipped) · test:module.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JS8ypVfQSFzYVZzkTHhURb


Generated by Claude Code

Port of nuxt/ui@8a25c22b, third in the `Link` prefetch chain after `c4ee0ea3`
(#538) and `612ab1cb` (#541), and a consequence of the second: `onNuxtReady`
put a second deferral in front of the idle callback, so the spec's flat 10 ms
wait sat in front of a two-step chain while still doing a non-null
`instances[0]!`.

Applies verbatim — the file was byte-identical to upstream's pre-image.

The measurement cuts against the commit subject: registration completes in 2 ms
here, three runs of three, so the old 10 ms had a 5x margin and nothing was
failing. This guards a loaded CI runner rather than repairing a break.

The real gain is an assertion, not a timeout. `instances[0]!` reads the first
observer and ignores any others; `waitForObserver` asserts `toHaveLength(1)`,
and `observeIntersection` shares one `IntersectionObserver` across every link —
so "exactly one" is the invariant that sharing holds, and nothing asserted it
before. Constructing a second observer per call turns 1 red on the port and
leaves 5 passed on the pre-image.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JS8ypVfQSFzYVZzkTHhURb
@IgorShevchik
IgorShevchik merged commit 6ae5680 into main Sep 7, 2026
2 checks passed
@IgorShevchik
IgorShevchik deleted the sync/nuxt-8a25c22b branch September 7, 2026 07:46
IgorShevchik added a commit that referenced this pull request Sep 7, 2026
`8a25c22b` went in with `pending-merge` in both `pr` and `b24ui_sha`, because
the entry is written in the same commit as the port, before its PR has a number
or a squash SHA. That PR has now merged:

- `8a25c22b` → #543 / `6ae5680d`

Bookkeeping only — no entry is added, the cursor does not move, and no decision
changes. The cursor stays at `8a25c22b`, which is nuxt/ui v4 HEAD, so the sync
is caught up and no entry carries the placeholder.


Claude-Session: https://claude.ai/code/session_01JS8ypVfQSFzYVZzkTHhURb

Co-authored-by: Shevchik Igor <noreply@anthropic.com>
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.

2 participants