Skip to content

feat!: remove Next/Nuxt nested bag API and expose/shared aliases - #1929

Merged
yamcodes merged 6 commits into
v1from
cursor/remove-nested-bag-api-7f13
Sep 21, 2026
Merged

yamcodes merged 6 commits into
v1from
cursor/remove-nested-bag-api-7f13

Conversation

@yamcodes

@yamcodes yamcodes commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Removes the deprecated nested arkenv({ server, client, shared, runtimeEnv }) overload and expose / shared option aliases from @arkenv/nextjs and @arkenv/nuxt.
  • Flat arkenv(schema, { exposeToClient, runtimeEnv }) is the only supported path; legacy callers throw a migration-oriented error at runtime, and @arkenv/build / static extraction reject the same shapes in schema source.
  • Shares detection + messaging via @repo/utils/nested-bag-migration-error (value-aware nested detection, dotted wrappers like at.type({…}) / z.object({…}), expose/shared throw).
  • Migration guide documents the break under Removed in v1, alongside the separate ArkEnvScript removal from v1.

Fixes #1910

Test plan

  • Unit tests for nextjs / nuxt / build / utils nested-bag paths
  • Merge origin/v1 and resolve conflicts (migration guide + new-features.test.tsx)
  • Re-run affected package tests after merge (269 passed)
Open in Web Open in Cursor 

Drop the deprecated nested arkenv({ server, client, shared, runtimeEnv })
overload and expose/shared option aliases from @arkenv/nextjs and
@arkenv/nuxt. Flat arkenv(schema, { exposeToClient }) is the only path;
legacy callers get a migration-oriented error. @arkenv/build extractKeys
rejects nested schema source the same way.

Fixes #1910

Co-authored-by: Yam Borodetsky <[email protected]>
@changeset-bot

changeset-bot Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 672db1b

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

This PR includes changesets to release 6 packages
Name Type
@arkenv/nextjs Major
@arkenv/nuxt Major
@arkenv/build Major
@arkenv/bun-plugin Patch
@arkenv/rsbuild-plugin Patch
@arkenv/vite-plugin 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

@yamcodes yamcodes added docs Adds or changes documentation, or acts as documentation in and of itself enhancement New feature or improvement @arkenv/nextjs Issues or Pull Requests involving the Next.js integration for ArkEnv @arkenv/nuxt Issues or Pull Requests involving the Nuxt integration for ArkEnv labels Sep 21, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@arkenv/agent-plugin

npm i https://pkg.pr.new/@arkenv/agent-plugin@1929

arkenv

npm i https://pkg.pr.new/arkenv@1929

@arkenv/build

npm i https://pkg.pr.new/@arkenv/build@1929

@arkenv/bun-plugin

npm i https://pkg.pr.new/@arkenv/bun-plugin@1929

@arkenv/core

npm i https://pkg.pr.new/@arkenv/core@1929

@arkenv/fumadocs-ui

npm i https://pkg.pr.new/@arkenv/fumadocs-ui@1929

@arkenv/nextjs

npm i https://pkg.pr.new/@arkenv/nextjs@1929

@arkenv/nuxt

npm i https://pkg.pr.new/@arkenv/nuxt@1929

@arkenv/rsbuild-plugin

npm i https://pkg.pr.new/@arkenv/rsbuild-plugin@1929

@arkenv/standard

npm i https://pkg.pr.new/@arkenv/standard@1929

@arkenv/tanstack-addon

npm i https://pkg.pr.new/@arkenv/tanstack-addon@1929

@arkenv/vite-plugin

npm i https://pkg.pr.new/@arkenv/vite-plugin@1929

commit: 672db1b

@github-actions github-actions Bot added example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) www Improvements or additions to arkenv.js.org tests This issue or PR is about adding, removing or changing tests playground Issues or Pull Requests concerning a playground. (Found in the `apps/playgrounds/` directory) labels Sep 21, 2026
Deduplicate the Next/Nuxt/build helpers into
@repo/utils/nested-bag-migration-error (from PR #1928), keeping
value-aware detection so flat keys named server are not misclassified.

Co-authored-by: Yam Borodetsky <[email protected]>

@pullfrog pullfrog Bot 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.

ℹ️ No critical issues — two rough edges worth a look.

Reviewed changes

  • @arkenv/nextjs flat-only — nested overloads and the expose / shared alias fields are gone; index.ts, react-server.ts, and standard/index.ts now call a value-aware assertNotRemovedNestedBag(schema) before arkenvInternal, and codegen always uses generateFlatFactoryCode.
  • @arkenv/nuxt flat-only — the same cut across the ArkType/Standard entries, parseSchemaShape, capture, and thin-accessor; ParsedSchemaShape.isLegacy is dropped.
  • @arkenv/build rejects nested source — extractKeys is flat-only, throws REMOVED_NESTED_BAG_MESSAGE on nested bag source, drops the isLegacy field, and stops matching the expose / shared option aliases; the new detection helpers are exported.
  • Docs, changeset, tests — the migration guide gains a "Removed in v1" section, the Next/Nuxt references note the flat-only shape, and nested/alias tests are replaced with flat plus rejection cases; major changesets for the three packages.

ℹ️ Nested buckets that are a single validator slip past the detector

isRemovedNestedBag treats a server / client / shared value as a bag only when it is a plain object without ~standard, so a nested call whose bucket is a single validator is not rejected: ArkType type({...}) returns a function (fails isPlainObject), and Zod z.object({...}) / Valibot v.object({...}) are plain objects that carry ~standard. The removed config.test.ts case "should extract keys when using ArkType type({...}) wrapper" shows this source form existed, so arkenv({ server: type({...}), client: type({...}) }) now falls through to the flat path and produces a downstream validation error instead of the migration message. This is a deliberate trade-off — flat env keys literally named server must keep working — so it is a judgment call whether to tighten detection or document the boundary.

Technical details
# Nested single-validator buckets bypass the migration detector

## Affected sites
- `packages/nextjs/src/removed-nested.ts:40` (`isSchemaBag`) and `:58` (bucket loop)
- `packages/nuxt/src/removed-nested.ts` — byte-identical copy, same lines
- Call sites: `packages/nextjs/src/index.ts:61`, `packages/nextjs/src/react-server.ts:33`, `packages/nextjs/src/standard/index.ts:47`, `packages/nuxt/src/thin-accessor.ts:23`, `packages/nuxt/src/schema-shape.ts:55`

## Required outcome
- Decide whether the migration guard should also catch nested buckets whose value is a single Standard Schema validator or an ArkType `type(...)` instance, or explicitly document that only record-shaped buckets are detected.

## Open questions for the human
- Was `server: type({...})` / `server: z.object({...})` ever a runtime-supported nested shape, or only ever handled by the static extractor?

ℹ️ Nitpicks

  • packages/nextjs/src/removed-nested.ts and packages/nuxt/src/removed-nested.ts are byte-identical 85-line copies, and REMOVED_NESTED_BAG_MESSAGE is a third copy in @arkenv/build/src/removed-nested.ts; hoisting the value-aware detector and message into a shared internal module would remove the drift risk.
  • hasRemovedNestedBagSource (packages/build/src/removed-nested.ts:21) is a raw-text regex with no comment or string awareness, so a schema file containing server: { inside a comment or string default would throw a spurious migration error during codegen/build. Latent only — no in-repo fixture triggers it.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

ℹ️ Incremental review — the @repo/utils refactor is clean; no new issues.

Reviewed changes

  • Shared migration helper moved to @repo/utils — the value-aware detector, source regex, and message now live in packages/internal/utils/src/utils/nested-bag-migration-error.ts behind a new ./nested-bag-migration-error subpath export, with its own unit tests; the three per-package src/removed-nested.ts copies are deleted.
  • @arkenv/build consumes the shared helper — core.ts imports hasNestedBagSource / assertNotNestedBagSource / nestedBagMigrationErrorMessage from @repo/utils, and the build index no longer re-exports them.
  • Call sites pass the second argument — assertNotNestedBag(schema, options) in the Next.js and Nuxt entries; isNestedBagCall additionally rejects a boolean second argument, covered by the new tests.

The two findings from the initial review — the migration guide's runtime-error claim for the expose / shared aliases, and nested buckets that are a single validator slipping past the detector — are unchanged by this commit and still stand.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Address review: option aliases now throw a migration error at runtime
and during static extraction (matching the migration guide), ArkType
type() bucket wrappers are detected, and source regex covers
`server: type(` forms.

Co-authored-by: Yam Borodetsky <[email protected]>
@yamcodes

Copy link
Copy Markdown
Owner Author

Addressed the open review findings in 12b83ee:

Finding Action
Migration guide claimed aliases throw, but they were silent Fixed — expose / shared now throw a migration error at runtime and in static extraction
Nested server: type({…}) slipped past the detector Fixed — functions (ArkType type()) count as bags; source regex also matches server: type(
Nested server: z.object({…}) still has ~standard Documented trade-off — the supported nested Standard shape was a Record of per-key validators (server: { KEY: z.string() }), which is already detected; a single z.object wrapping a whole bucket was not a documented nested form. Flat env keys named server with a Standard Schema validator must keep working
Shared helper drift Already addressed in the prior commit (@repo/utils/nested-bag-migration-error)

@pullfrog pullfrog Bot 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.

ℹ️ No critical issues — one minor documentation/regex mismatch inline.

Reviewed changes

  • expose / shared aliases now throw — assertNotNestedBag detects the removed option keys on the second argument and throws removedExposeAliasErrorMessage(), and assertNotRemovedExposeAliasSource rejects them during @arkenv/build extraction and Next.js codegen. This closes the gap where the aliases were silently ignored.
  • ArkType type() buckets now detected — isSchemaBag treats any function as a nested bag, and hasNestedBagSource matches bare type( wrapper calls in source.
  • Migration guide wording tightened — the "Removed in v1" section now states that call sites still using the removed shapes throw at runtime and that static key extraction rejects the same shapes in schema source, matching the new behavior.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Extend hasNestedBagSource so at.type({…}) / z.object({…}) match, while
flat server: z.string() still does not. Align the JSDoc with the regex.

Co-authored-by: Yam Borodetsky <[email protected]>

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

This run re-reviewed the single commit pushed since the last pullfrog review (bfd77e4, fix: detect dotted nested bag wrappers in source).

  • Source guard now catches dotted object wrappers — hasNestedBagSource allows dotted call targets and requires ( immediately followed by {, so client: at.type({…}) and server: z.object({…}) now throw during static extraction while a flat single-validator key such as server: z.string() no longer false-positives.
  • JSDoc and tests updated to match — the doc comment documents the ( + { wrapper requirement, and the unit test adds at.type / z.object positives plus a z.string() negative, so the assertion fails if the regex regresses.
  • Prior thread resolved — the earlier inline concern about z.object( / at.type( not matching is addressed by this commit.

The remaining known boundary (a wrapper that takes a variable rather than an inline object, e.g. server: type(serverSchema), is caught at runtime but not by the static guard) is documented in the JSDoc and was already surfaced in the initial review, so it is not re-raised here.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Resolve conflicts with ArkEnvScript removal: keep both migration
sections, drop script/__arkenv_env__ tests, retain nested-bag throw
coverage and flat codegen assertions.

Co-authored-by: Yam Borodetsky <[email protected]>

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

This run re-reviewed the single commit pushed since the last pullfrog review — 672db1b, the merge of origin/v1 into the branch, whose only authored delta is the conflict resolution.

  • Migration guide conflict resolved — apps/www/content/docs/guides/migrating-to-v1.mdx keeps v1's new "Next.js ArkEnvScript removed" section directly above the PR's "Removed in v1" section, so both the ArkEnvScript cut and the nested-bag/alias removal are documented and the #removed-in-v1 anchor linked from the Next/Nuxt references still resolves.
  • new-features.test.tsx conflict resolved — the obsolete ArkEnvScript / __arkenv_env__ / dynamic-client-lookup tests and the vi import are dropped (matching v1's removal), while the nested-bag throw test and the flat codegen assertion are retained; the assertion now expects NEXT_PUBLIC_VAL: process.env.NEXT_PUBLIC_VAL, plus not.toContain("__arkenv_env__"), matching generateFlatFactoryCode.
  • Consistency verified — no dangling ArkEnvScript, __arkenv_env__, isLegacy, LegacyNestedSchema, or generateFactoryCode references remain in source; @arkenv/nextjs (48 tests) and @arkenv/nuxt (48 tests) pass after building the affected packages.

The previously flagged known boundary (a nested bucket that is a single Zod/Valibot validator slips the runtime detector; the static source guard now catches it) is unchanged by this commit and remains a documented judgment call, not re-raised.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@yamcodes
yamcodes merged commit 0d2f24b into v1 Sep 21, 2026
21 checks passed
@yamcodes
yamcodes deleted the cursor/remove-nested-bag-api-7f13 branch September 21, 2026 11:02
@arkenv-bot arkenv-bot Bot mentioned this pull request Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@arkenv/nextjs Issues or Pull Requests involving the Next.js integration for ArkEnv @arkenv/nuxt Issues or Pull Requests involving the Nuxt integration for ArkEnv docs Adds or changes documentation, or acts as documentation in and of itself enhancement New feature or improvement example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) playground Issues or Pull Requests concerning a playground. (Found in the `apps/playgrounds/` directory) tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Next/Nuxt nested bag API and expose/shared aliases

2 participants