Repository navigation
fix(bundler-webpack): externalize vue subpaths in ssr bundle (close #1718) - #1725
Merged
Mister-Hope merged 1 commit intoSep 29, 2026
Merged
Conversation
…1718) The server bundle only externalized `vue` itself. The array form of webpack `externals` matches requests exactly, so `vue/server-renderer`, which SFCs compiled for SSR import from, was resolved to `@vue/server-renderer` and bundled together with its own copies of `@vue/runtime-core` and `@vue/shared`, while `vue` stayed external. With two vue runtimes in one server bundle, components are created by the bundled runtime, and `instance.refs` is the bundled `EMPTY_OBJ`, but `useTemplateRef` comes from the external `vue` and compares it with its own `EMPTY_OBJ`. With the production build of vue, the check never matches, so the ref is defined as a non-configurable property on the shared `EMPTY_OBJ`, and rendering another page that uses the same ref key throws `Cannot redefine property`, leaving the page content empty in the generated HTML. Externalize `vue` and all of its subpaths. `@vue/*` packages are not externalized, because they are not guaranteed to be resolvable from the temp directory with pnpm, e.g. `@vue/devtools-api`.
3 of 6 tasks
Mister-Hope
approved these changes
Sep 29, 2026
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.
Before submitting the PR, please make sure you do the following
close #123).What is the purpose of this pull request?
Description
close #1718
Root cause
As analyzed in #1718, the webpack server bundle only externalizes
vueitself:The array form of webpack
externalsmatches requests exactly, sovue/server-renderer, which SFCs compiled for SSR import from, is resolved to@vue/server-rendererand bundled together with its own copies of@vue/runtime-coreand@vue/shared, whilevuestays external. Components are created by the bundled runtime, soinstance.refsis the bundledEMPTY_OBJ, butuseTemplateRefcomes from the externalvueand compares it with its ownEMPTY_OBJ. With the production build of vue the check never matches, so the ref is defined as a non-configurable property on the sharedEMPTY_OBJ, and rendering another page that uses the same ref key throwsCannot redefine property. The error is logged and the build still succeeds, but the content of that page is empty in the generated HTML.Fix
Externalize
vueand all of its subpaths:@vue/*packages are not externalized as proposed in #1718, because they are not guaranteed to be resolvable from the temp directory with pnpm. Trying it on the e2e site failed withCannot find module '@vue/devtools-api'. Onlyvueis guaranteed to be resolvable, as it is a peer dependency of the site.Server bundle of the e2e site (
vuepress build docs --debugwith the webpack bundler):app.cjssize@vue/runtime-core@vue/server-renderervuevue,vue/server-rendererTests
Added two e2e pages that use
useTemplateRefwith the same key, and a test that checks both pages are rendered, including their SSR HTML in build mode (the same way asimports/conditional-exports.spec.ts). Without the fix,e2e:build:webpackfails on whichever page is rendered second:Verification
pnpm lint,pnpm check-types,pnpm test:unit(63 files, 666 tests): pass.e2e:build:webpack91 passed,e2e:dev:webpack84 passed,e2e:build90 passed,e2e:dev82 passed and 1 failed (hmr.spec.ts› "should update content and frontmatter and title correctly after navigation", which is flaky locally, failing once and passing once on rerun; the vite dev server is not affected by this change).Screenshots
N/A