Skip to content

test(pages): cover loader and action updates to shared data - #699

Merged
Brooooooklyn merged 2 commits into
mainfrom
fix/page-action-shared
Nov 4, 2026
Merged

Brooooooklyn merged 2 commits into
mainfrom
fix/page-action-shared

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Fixes #695

What I found

main already reads shared after the loader and action run (changed in #624). The issue's table was checked on 1.5.0, which read it before they ran.

issue row                          1.5.0     main
─────────────────────────────────  ────────  ──────────────────────────
action  c.set('shared', …)         stale     updated
loader  c.set('shared', …)         stale     updated
action/loader Object.assign        updated   updated
action changes the DB only         stale     stale (by design, see below)

Why the last row stays:

request ─► middleware sets shared ─► action ─► loader ─► page { props, shared }
                                       │
              changes the DB here ─────┘   middleware does not run again

The action (or the loader) can update shared, or redirect so that middleware runs again on the next page load. All four adapters (React, Vue, Svelte, Solid) replace shared with the value from each new page response, including after an action. This was checked by reading the code and in a browser against the playground builds.

This PR

  • Tests (pages-protocol.test.ts, routing-runtime.test.ts):

    • loader update on GET
    • action update in the JSON page and in the HTML page
    • action update kept when the action then throws a ValidationError
    • a loader that runs after an action sees the action's update
    • an action that leaves shared alone keeps the middleware value

    With the old early read, 5 of the new tests fail.

  • Docs: layouts.md shows a loader or action updating shared, actions-and-forms.md says middleware does not run again after an action, and the useShared() rows in the API reference now mention loaders and actions.

  • Test flake (separate commit): jsx-websocket.test.ts copies playground/websockets while websockets-playground.test.ts rebuilds it in place. The copy could hit a file the build just removed (ENOENT … .cloudflare/output/…/assets/.vite). .cloudflare is build output, so the copy helper now skips it, as it already skips dist and .void.

Not changed

  • Deferred-prop resolvers run after the page is built, so they can't change shared.
  • Island-mode actions return no page.
  • Route middleware that changes shared after next() runs too late.

These are separate from this issue.

Verification

  • vp test run on the two test files (-t shared): 7 passed
  • vp run test: 773 files passed
  • vp run check: 33/33

🤖 Generated with Claude Code

Brooooooklyn and others added 2 commits November 4, 2026 13:25
Middleware sets the starting `shared` value. Since #624 the page object reads
it after the loader and action run, so `c.set('shared', ...)` and in-place
changes in a loader or action reach the page. Nothing tested that.

Add tests for the JSON and HTML page after an action, a validation error,
a loader on GET, the loader that runs after an action, and an action that
leaves shared data alone (it keeps the middleware value). Document that
loaders and actions can update shared data and that middleware does not run
again after an action.

Fixes #695

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
websockets-playground.test.ts builds playground/websockets in place while
jsx-websocket.test.ts copies the same folder. The build rewrites
.cloudflare/output, so the copy could hit a removed file and fail with
ENOENT. .cloudflare is build output, like dist and .void, so do not copy it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T05:26:49.510933Z b26e972 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-page-action-shared-void-cloud.voidzero-docs.workers.dev (commit b26e972)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://ab3f134a-void-cloud.voidzero-docs.workers.dev b26e972 2026-11-04T05:27:28.778Z Visit the dashboard ↗

@Brooooooklyn
Brooooooklyn merged commit 7c33d23 into main Nov 4, 2026
20 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/page-action-shared branch November 4, 2026 06:11
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.

Page actions send the shared data from before the action ran

1 participant