fix(server-core): share hono context storage across duplicated module copies - #8776
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 1e1815e The changes in this PR will be included in the next version bump. This PR includes changesets to release 118 packages
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 |
✅ Deploy Preview for modernjs-byted ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
pnpm peer-variant duplication can load two copies of @modern-js/server-core in one process; the host writes the request context through one copy's module-scoped AsyncLocalStorage while plugin-bff reads through the other, failing with "Can't call useContext out of server scope". Key the context storage on globalThis via Symbol.for so every copy shares one store.
keepview
force-pushed
the
fix/server-core-global-context-storage
branch
from
July 22, 2026 11:40
8395e9e to
1e1815e
Compare
zllkjc
approved these changes
Jul 23, 2026
keepview
added a commit
that referenced
this pull request
Sep 15, 2026
…SR bundle The externals entry (#7236) kept `useHonoContext()` in loaders on the same AsyncLocalStorage as the server. Since #8776 that storage is registered on `globalThis[Symbol.for('@modern-js/server-core/hono-context')]`, so every loaded copy of server-core/server-runtime shares it and the externals entry no longer serves a purpose. What it caused instead: applications depend on a re-export wrapper (for example `@edenx/server-runtime`), so the SSR bundle carried a bare `require("@modern-js/server-runtime")` on a transitive dependency. Under pnpm's strict layout that name does not resolve from the application root, deploy-time dependency tracing dropped it silently, and the bundle failed at runtime with `Cannot find module '@modern-js/server-runtime'`, degrading the whole page to client rendering unless something else in the artifact happened to require the wrapper. Remove the plugin and add a deploy-test assertion that no output script requires the package any more. Co-Authored-By: Riff Claude-Session: https://claude.ai/code/session_0114E5DwvH9oSbRb7ezmyLJb
keepview
added a commit
that referenced
this pull request
Sep 15, 2026
…SR bundle The externals entry (#7236) kept `useHonoContext()` in loaders on the same AsyncLocalStorage as the server. Since #8776 that storage is registered on `globalThis[Symbol.for('@modern-js/server-core/hono-context')]`, so every loaded copy of server-core/server-runtime shares it and the externals entry no longer serves a purpose. What it caused instead: applications depend on a re-export wrapper (for example `@edenx/server-runtime`), so the SSR bundle carried a bare `require("@modern-js/server-runtime")` on a transitive dependency. Under pnpm's strict layout that name does not resolve from the application root, deploy-time dependency tracing dropped it silently, and the bundle failed at runtime with `Cannot find module '@modern-js/server-runtime'`, degrading the whole page to client rendering unless something else in the artifact happened to require the wrapper. Remove the plugin and add a deploy-test assertion that no output script requires the package any more. Co-Authored-By: Riff Claude-Session: https://claude.ai/code/session_0114E5DwvH9oSbRb7ezmyLJb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
pnpm peer-variant duplication can load two copies of
@modern-js/server-corein one process. Since the hono request context lives in a module-scopedAsyncLocalStorage, the host writes the context through one copy while@modern-js/plugin-bff's decorators read through the other, failing with:This PR keys the request-context storage on
globalThisviaSymbol.for, so every loaded copy shares oneAsyncLocalStorage:createStoragegains an optionalglobalKeyparameter — without it the behavior is byte-for-byte unchanged (other/generic uses unaffected;context.tsis the only call site today);Related Links
Checklist
pnpm run change.