Skip to content

Fix viem imports under SES lockdown() - #5306

Merged
jxom merged 1 commit into
mainfrom
jxom/wonderful-knuth-5f5il1
Oct 26, 2026
Merged

jxom merged 1 commit into
mainfrom
jxom/wonderful-knuth-5f5il1

Conversation

@jxom

@jxom jxom commented Oct 26, 2026

Copy link
Copy Markdown
Member

What is this PR solving?

This PR fixes importing viem and its entrypoints (viem/actions, viem/chains, etc.) when running under SES lockdown(), which freezes intrinsic prototypes. Previously, this would throw Cannot assign to read only property 'call' because the emitted code attempted to assign namespace members that shadow intrinsic prototype properties (e.g., getAllowance.call = call).

Solution

The fix involves two main changes:

  1. New hardenNamespaces.ts script: A TypeScript utility that post-processes emitted JavaScript files to rewrite namespace member assignments that shadow intrinsic properties. Instead of direct assignment (which fails under frozen intrinsics), it uses Object.defineProperty() with identical property descriptors, which succeeds even with frozen prototypes.

  2. Build pipeline integration: The script is now run during both CJS and ESM builds to harden all emitted namespace members.

  3. SES test environment: Added a new test environment (environments/ses/) that validates viem works correctly under SES lockdown() by:

    • Freezing intrinsics before importing viem
    • Testing actual viem functionality (e.g., token.getAllowance.call())
    • Running in both CommonJS and ESM contexts

The CI workflow has been updated to run this new SES test environment as part of the verification matrix.

Test Plan

The new SES test environment (environments/ses/) is automatically run in CI and validates that viem can be imported and used under frozen intrinsics. Existing tests continue to pass.

https://claude.ai/code/session_01USP6moK1yHGUDpsGiNTiKR

…in build output

TypeScript emits `export namespace getAllowance { export function call() }`
as `getAllowance.call = call`. Under frozen intrinsics (SES `lockdown()`),
`Function.prototype.call` is read-only, so the assignment throws on import
of `viem`, `viem/actions`, `viem/chains`, and other entrypoints.

`scripts/hardenNamespaces.ts` runs after `build:esm` and `build:cjs`. It
rewrites each emitted namespace member assignment whose name shadows a
`Function.prototype` or `Object.prototype` property into
`Object.defineProperty`, with the same descriptor. The source, the public
API, and the `.d.ts` output do not change. `environments/ses` imports every
entrypoint (CJS and ESM) after `lockdown()`.

Addresses the import crash in #5248.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01USP6moK1yHGUDpsGiNTiKR
@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Ready Ready Preview Oct 26, 2026 7:56am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eb0d67c

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

This PR includes changesets to release 1 package
Name Type
viem 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 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-10-26T08:05:19.723150Z eb0d67c 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.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedses@​2.3.010010010093100

View full report

@jxom
jxom merged commit 30833ec into main Oct 26, 2026
37 of 40 checks passed
@jxom
jxom deleted the jxom/wonderful-knuth-5f5il1 branch October 26, 2026 07:58
@github-actions github-actions Bot mentioned this pull request Oct 26, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb0d67cebb

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/hardenNamespaces.ts Resolved

This branch was successfully deployed

1 active deployment
Preview — eb0d67ce Deployed Oct 26, 2026 by vercel[bot]
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