Skip to content

fix: render server action redirects for the host of the request - #1414

Merged
vicb merged 3 commits into
opennextjs:mainfrom
allangreatsoftwares:fix/per-request-next-private-origin
Oct 16, 2026
Merged

vicb merged 3 commits into
opennextjs:mainfrom
allangreatsoftwares:fix/per-request-next-private-origin

Conversation

@allangreatsoftwares

@allangreatsoftwares allangreatsoftwares commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1413.

init() sets process.env.__NEXT_PRIVATE_ORIGIN once per isolate from the first request. Next fetches the target of a server action redirect from that origin, so a worker serving several hosts renders the redirect for whichever host initialized the isolate (in production: users of one tenant sent to another tenant's login).

The assignment came from #689, to fix the protocol in preview over http. Since f1e9457 the attachRequestMeta patch keeps the request protocol in initURL, which Next uses when __NEXT_PRIVATE_ORIGIN is undefined, so the global is no longer needed. It is removed.

A getter on process.env reading an AsyncLocalStorage would have kept the variable per request, but workerd rejects it (process.env value must not have getter/setter).

Tests

  • New e2e in app-router: the same redirecting action is submitted from localhost and 127.0.0.1, each must render its own host.
  • Checked manually against the example in preview (http): without the fix, after localhost initializes the isolate, the action from 127.0.0.1:8790 renders Rendered for host: localhost:8790. With the fix both hosts render their own host.
  • pnpm code:checks and pnpm --filter cloudflare test pass.

@changeset-bot

changeset-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e7bf1f2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@allangreatsoftwares
allangreatsoftwares force-pushed the fix/per-request-next-private-origin branch from 6874df8 to 5a5e711 Compare October 2, 2026 20:50
@allangreatsoftwares
allangreatsoftwares marked this pull request as ready for review October 14, 2026 05:33

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@vicb
vicb force-pushed the fix/per-request-next-private-origin branch from bac2d4d to e7bf1f2 Compare October 16, 2026 09:26
@pkg-pr-new

pkg-pr-new Bot commented Oct 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@opennextjs/cloudflare@1414

commit: e7bf1f2

@vicb vicb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @allangreatsoftwares 🙏

I have sync'd with main and move the e2e test to a cloudflare specific app (examples/e2e apps are shared with the aws adapter)

@vicb
vicb merged commit 15f4c9e into opennextjs:main Oct 16, 2026
7 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.

[BUG] Server Action redirects are rendered for the host that initialized the isolate

3 participants