test(Link): wait for the visibility observer instead of a fixed timeout - #543
Merged
Conversation
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
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>
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.
Port of
nuxt/ui@8a25c22b— third in theLinkprefetch chain afterc4ee0ea3(#538) and612ab1cb(#541), and a consequence of the second.612ab1cbput the visibility observer behindonNuxtReady, so registration now runs through two deferrals instead of one. The spec still waited a flat 10 ms and then did a non-nullinstances[0]!on a value that might not be there yet. Upstream replaces that with avi.waitFor-basedwaitForObserver()for the positive case, and liftsidle()to 50 ms for the two negative cases — which cannot poll for something meant never to appear.Applies verbatim.
test/components/nuxt/LinkPrefetch.spec.tswas byte-identical to upstream's pre-image, checked with a whole-filediffagainst612ab1cb, 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
mainafter #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.waitForObserverassertstoHaveLength(1)— andobserveIntersectionshares oneIntersectionObserveracross 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:
observeIntersectionreturns without observingIntersectionObserverper call (sharing broken)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— cursor612ab1cb→8a25c22b, entry added with thepending-mergeplaceholder 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