Skip to content

fix: public ENV replacement in next client components#508

Open
melkir wants to merge 1 commit intodmno-dev:mainfrom
melkir:codex/fix-next-client-env-turbopack
Open

fix: public ENV replacement in next client components#508
melkir wants to merge 1 commit intodmno-dev:mainfrom
melkir:codex/fix-next-client-env-turbopack

Conversation

@melkir
Copy link
Copy Markdown

@melkir melkir commented Mar 30, 2026

Summary

Fix public ENV.* replacement in Next client components.

Previously, the Next loader returned early for 'use client' modules, which meant Turbopack client code skipped the non-sensitive static replacement pass entirely.

What changed

  • stop bailing out early for client components in the Next loader
  • keep the server-only init injection disabled for client modules
  • detect Turbopack from the worker environment so the public ENV.* replacement path still runs there

Root cause

Two things combined to break ENV.NEXT_PUBLIC_* in client components under Turbopack:

  • the loader skipped all client components before it reached the static replacement logic
  • the loader could not rely on explicit loader options to identify Turbopack in that path

That left ENV.NEXT_PUBLIC_* as a runtime lookup in client code instead of being inlined like other public env access.

Impact

Client code can now read public env values through ENV.NEXT_PUBLIC_* under Turbopack without pulling in the server-only init snippet.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 30, 2026

⚠️ No Changeset found

Latest commit: e03b950

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@melkir melkir force-pushed the codex/fix-next-client-env-turbopack branch from 515049a to e03b950 Compare March 30, 2026 11:44
@melkir melkir changed the title [codex] Fix Next.js client-side ENV access in Turbopack [codex] Fix public ENV replacement in Next client components Mar 30, 2026
@melkir melkir changed the title [codex] Fix public ENV replacement in Next client components fix: public ENV replacement in next client components Mar 30, 2026
@melkir melkir marked this pull request as ready for review March 30, 2026 11:50
@philmillman philmillman requested a review from theoephraim March 30, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant