Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip injecting __vite__mapDeps when it's not used #16271

Merged
merged 2 commits into from Mar 26, 2024

Conversation

hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Mar 26, 2024

Description

Following the suggestion #15732 (comment), I skipped injecting __vite__mapDeps when it's not used.

This will cover non browser cases where preload is not used at all (see insertPreload) since fileDeps will be empty in the end for those cases as well.

const insertPreload = !(ssr || !!config.build.lib || isWorker)

Here is a change of playground/js-sourcemap/after-preload-dynamic-no-dep.js build output:

before
function __vite__mapDeps(indexes) {
  if (!__vite__mapDeps.viteFileDeps) {
    __vite__mapDeps.viteFileDeps = [];
  }
  return indexes.map((i) => __vite__mapDeps.viteFileDeps[i]);
}
import { _ as o } from "./after-preload-dynamic-BAkr0czH.js";
o(() => import("./dynamic-no-dep-BZ-YzFGU.js"), __vite__mapDeps([]));
console.log("after preload dynamic no dep");
//# sourceMappingURL=after-preload-dynamic-no-dep-Df4YzL2T.js.map
after
import{_ as o}from"./after-preload-dynamic-BAkr0czH.js";
o(()=>import("./dynamic-no-dep-BZ-YzFGU.js"),[]);
console.log("after preload dynamic no dep");
//# sourceMappingURL=after-preload-dynamic-no-dep-Df4YzL2T.js.map

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.

Copy link

stackblitz bot commented Mar 26, 2024

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

@hi-ogawa hi-ogawa changed the title fix: remove unnecessary __vite__mapDeps fix: skip injecting __vite__mapDeps when it's not used Mar 26, 2024
@hi-ogawa hi-ogawa marked this pull request as ready for review March 26, 2024 02:13
@patak-dev
Copy link
Member

/ecosystem-ci run

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Nice! I think this looks good to be merged in a patch to me.

@sapphi-red
Copy link
Member

Thanks!

@sapphi-red sapphi-red merged commit 890538a into vitejs:main Mar 26, 2024
21 checks passed
@hi-ogawa hi-ogawa deleted the fix-unnecessary-mapDeps branch March 26, 2024 06:50
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.

None yet

3 participants