Skip to content

fix: scope getPageContext() in +onAfterRenderClient to its synchronous code (vikejs/vike#3759) - #248

Merged
brillout merged 5 commits into
vikejs:mainfrom
nitedani-agent:fix/providepagecontext-callback
Dec 3, 2026
Merged

brillout merged 5 commits into
vikejs:mainfrom
nitedani-agent:fix/providepagecontext-callback

Conversation

@nitedani-agent

@nitedani-agent nitedani-agent commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

ClaudeCodex Claude Fable 5.2 (high effort) and Claude Opus 5.5 (high effort) wrote this; GPT-6.2-Sol (Codex, high effort) reviewed it.

On the server, a getPageContext() after an await in +onAfterRenderHtml can return the pageContext of another request. vike-react 0.6.32 calls providePageContext(pageContext) before each render hook and each function set as +headHtmlEnd and alike, and Vike keeps that pageContext until its queued cleanup runs. This PR calls each of them inside providePageContext(pageContext, fn), as you asked, so getPageContext() returns that pageContext only in the hook's synchronous code. After an await, a hook has its pageContext argument.

Vike dee1dd8fd (vikejs/vike#3759), its test/vike-react app on vike preview vike-react 0.6.32 0.6.32 with this PR's change in its built callCumulativeHooks.js
getPageContext() after awaits in +onAfterRenderHtml, 1220 overlapping pairs of requests the other request's pageContext in 20 pairs null in all 1220
That Vike packed as 0.4.271, examples/full on vike dev vike-react 0.6.32 This PR (ccaeb16 with main at 0a83fa3 merged in locally, for its Playwright bump)
Vike's warning Update vike-react, vike-vue or vike-solid to its latest version once in the server's log, and once per page load in the browser's console not printed

require: { vike } and the vike peer dependency go from >=0.4.250 to >=0.4.271, because a Vike without the callback form ignores the callback, so the hook would never run. vike-react 0.6.32 keeps working on that Vike release, with the warning, so Vike can be released first. The squash body:

BREAKING CHANGE: Update Vike to `0.4.271` or above.

What you should see

1. Three hooks added to examples/full for the run. The server prints the first two lines, and the third is the attribute +onAfterRenderClient sets on <html>:

[hook-run] +onAfterRenderHtml for /star-wars: getPageContext() === pageContext -> true
[hook-run] async +onBeforeRenderHtml for /star-wars: before its first await getPageContext() === pageContext -> true; after it getPageContext() -> null
data-hook-run="+onAfterRenderClient for /star-wars: getPageContext() === pageContext -&gt; true"

2. Local runs on 457f23c, with the released vike@0.4.271 in the lockfile, on Node 22.23.4: build, type check (17 projects), unit tests and the format check of the tracked files exit 0, and the 19 e2e test files pass. 48b928f moves the Vike dev dependencies to ^0.4.271, as the earlier chore: vike@^… commits do, and test/sentry's too, whose type check failed on the older Vike next to this vike-react. 457f23c updates the page id assertion of examples/full for Vike 0.4.271, whose HTML escapes each slash of the page id as \/, where its .testRun.ts replaced \\/.

🤖 Generated with Claude Code

…`vike@0.4.271` (vikejs/vike#3759)

BREAKING CHANGE: Update Vike to 0.4.271 or above.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@nitedani-agent

Copy link
Copy Markdown
Contributor Author

ClaudeCodex Claude Fable 5.2 (high effort) wrote this; GPT-6.2-Sol (Codex, high effort) reviewed it.

The Windows jobs stop at the build. CI installed Vike 0.4.259, which has no providePageContext(pageContext, fn), so the changed line fails on TS2554: Expected 1 arguments, but got 2, and the void that call returns fails on TS2322 (log).

The Ubuntu jobs stop before that, at pnpm install. This run got Ubuntu 26.04 for ubuntu-latest (the last green run, on 2026-11-13, got Ubuntu 24.04), and the install script of playwright-chromium@1.57.0 throws Playwright does not support chromium on ubuntu26.04-x64 (log). main locks the same Playwright, so I think its next run that gets Ubuntu 26.04 fails the same way.

I'll open a PR that bumps playwright-chromium to a version that supports Ubuntu 26.04, by 2026-11-23T20:00Z.

@nitedani-agent nitedani-agent changed the title fix: +onAfterRenderClient and the other cumulative hooks work with vike@0.4.271 (vikejs/vike#3759) fix: another request can't read the pageContext provided to a render hook (vikejs/vike#3759) Nov 23, 2026
nitedani-agent and others added 3 commits December 3, 2026 15:48
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The page id in `<script id="vike_pageContext">` has its slashes escaped as `\/`, so `findFirstPageId()` replaces that and not `\\/`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nitedani-agent
nitedani-agent marked this pull request as ready for review December 3, 2026 15:06
@brillout brillout changed the title fix: another request can't read the pageContext provided to a render hook (vikejs/vike#3759) fix: scope getPageContext() in +onAfterRenderClient to its synchronous code (vikejs/vike#3759) Dec 3, 2026
@nitedani-agent

Copy link
Copy Markdown
Contributor Author

ClaudeCodex Claude Opus 5.5 (high effort) wrote this; GPT-6.2-Sol (Codex, medium effort) reviewed it.

@brillout Ready for review at 457f23c, on vike@0.4.271, and CI passes (5 of 5). Besides the chore: vike@^0.4.271 bump, which also moves test/sentry, 457f23c updates a page id assertion of examples/full for 0.4.271, which escapes the slashes of the page id differently.

@brillout
brillout merged commit 63bf285 into vikejs:main Dec 3, 2026
5 checks passed
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