Skip to content

fix(ssr): apply alias to resolvable dependencies during dev#15602

Merged
bluwy merged 7 commits into
vitejs:mainfrom
hi-ogawa:fix-ssr-import-analysis-alias-not-external
Mar 12, 2024
Merged

fix(ssr): apply alias to resolvable dependencies during dev#15602
bluwy merged 7 commits into
vitejs:mainfrom
hi-ogawa:fix-ssr-import-analysis-alias-not-external

Conversation

@hi-ogawa
Copy link
Copy Markdown
Contributor

@hi-ogawa hi-ogawa commented Jan 15, 2024

Description

I found this dev/build inconsistency while investigating the issue #15503 (comment), but the issue itself seems to be more complicated and currently it's waiting for proper reproduction. (EDIT: I think this is the only vite side issue, so we can close it if this PR is merged.)

Given that there is a big warning in https://vitejs.dev/guide/ssr.html#ssr-externals, I suppose relying on resolve.alias might not be recommended in general. However, considering this is one source of dev/build inconsistency for non-external modules, so I thought this is worth making it consistent. Please let me know if this fix is appropriate here.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines, especially the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@hi-ogawa hi-ogawa marked this pull request as ready for review January 15, 2024 01:30
@hi-ogawa hi-ogawa changed the title fix(ssr): apply alias to resolvable modules during dev fix(ssr): apply alias to resolvable dependencies during dev Jan 15, 2024
Comment on lines +4 to +11
test.runIf(isServe)('dev', async () => {
const mod = await viteServer.ssrLoadModule('/src/main.js')
expect(mod.default).toEqual({
dep: 'ok',
nonDep: 'ok',
builtin: 'ok',
})
})
Copy link
Copy Markdown
Contributor Author

@hi-ogawa hi-ogawa Jan 16, 2024

Choose a reason for hiding this comment

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

Previous behavior was that:

  {
    dep: 'original',
    nonDep: 'ok',
    builtin: undefined,
  }

which is inconsistent with build mode.

@patak-cat patak-cat added this to the 5.2 milestone Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssrLoadModule fails to respect preact/compat aliases, while the SSR bundle does respect preact/compat aliases

3 participants