Skip to content

fix(env): pass Object.prototype members through the env proxy - #725

Merged
cpojer merged 1 commit into
voidzero-dev:mainfrom
morinokami:fix/env-prototype-reads
Nov 5, 2026
Merged

cpojer merged 1 commit into
voidzero-dev:mainfrom
morinokami:fix/env-prototype-reads

Conversation

@morinokami

Copy link
Copy Markdown
Contributor

When env.ts registers a schema, reading an Object.prototype member from env throws:

import { env } from 'void/env';

env.hasOwnProperty('STRIPE_KEY');
env.constructor;
String(env);
TypeError: Cannot read properties of undefined (reading 'validate')

readKey looks the key up with registry.schema[key], which also finds inherited members, and treats them as validators. Without a schema, the same expressions work.

Fix

readKey checks the key with Object.hasOwn, so these members pass through like any key the schema doesn't declare.

Tests

packages/void/test/unit/env-schema.test.ts: the three reads above with a registered schema. The case fails without this fix.

Verification

  • vp test run: 776 files pass, 1 skipped (16,002 tests pass, 29 skipped).
  • vp run check: 33/33 pass.
  • By hand on a copy of playground/ssr with an env.ts: a route that makes these reads answers 200 in vp dev and vp preview.

🤖 Generated with Claude Code

`readKey` looked keys up with `registry.schema[key]`, which also finds
inherited members. With a schema registered, `env.hasOwnProperty`,
`env.constructor` and `String(env)` treated those members as validators
and threw a TypeError.

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

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

JavaScript…

@cpojer
cpojer merged commit dca03da into voidzero-dev:main Nov 5, 2026
2 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