Repository navigation
Interactivity Router tests: Wait through the unhydrated log after a reload - #87158
Conversation
…eload The lifecycle spec polls the fixture's log with `JSON.parse`. Right after a traversal or reload replaces the document, the log still holds the server-rendered `not hydrated` placeholder, so a poll tick that landed before hydration threw a `SyntaxError` instead of retrying. Poll through a reader that returns `null` for the placeholder, so the wait keeps going until the log has hydrated.
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: 0 B Total Size: 8.69 MB
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Navigates the list via UP/DOWN arrow keys from action buttons in
|
…eload (WordPress#87158) The lifecycle spec polls the fixture's log with `JSON.parse`. Right after a traversal or reload replaces the document, the log still holds the server-rendered `not hydrated` placeholder, so a poll tick that landed before hydration threw a `SyntaxError` instead of retrying. Poll through a reader that returns `null` for the placeholder, so the wait keeps going until the log has hydrated.
What?
Fixes a flaky wait in
test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts.Why?
The test "a navigation superseded by the traversal discharges to idle" passed only after a retry in CI, with:
The test ends with
history.back(), which reloads the document. Until the Interactivity API hydrates, the new page shows the server-renderednot hydratedplaceholder in thelifecycle logelement (router-navigation-lifecycle/render.php).waitForLogLengthpollsreadLog, which ranJSON.parseon that placeholder. When a poll tick landed before hydration it threw instead of retrying.Every test that polls right after a document replacement had the same race, for example the traversal tests and the ones that start with
page.goto().How?
readHydratedLog, which returnsnullwhile the log still shows thenot hydratedplaceholder.waitForLogLengthandwaitForTruthyLogEntry, the two polling helpers, use it, so an unhydrated page counts as "not there yet" and the poll keeps going.readLogis unchanged and still strict. Every directreadLogcall comes after one of those waits, so it only sees a hydrated log, and a malformed log still fails loudly instead of reading as empty.Testing Instructions
The failure is a timing race, so it can't be reproduced on demand. Run the spec and check that it still passes:
I have not run the spec locally. I only ran
npm run lint:json the file, which passes. The commit used--no-verifybecause the fresh worktree had no husky install, so thelint-stagedpre-commit hook could not run. CI will exercise the spec.Use of AI Tools
Claude (Sonnet 5.5, via OpenCode) diagnosed the failure from the CI log and wrote the change and this description.