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

Vite: Fix missing source map warning #28984

Merged

Conversation

valentinpalkovic
Copy link
Contributor

@valentinpalkovic valentinpalkovic commented Aug 27, 2024

Closes #28567

What I did

I have added a null byte to the resolveID for virtual files. Virtual modules should be prefixed with a null byte to avoid a
false positive "missing source" warning. Context: https://github.com/vitejs/vite/pull/5587/files#diff-414e1bd440bdc6c3c213c6f9cc712d2b29b1c1662b04a9daa9c02ee6bcca9432R11-R15

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This pull request has been released as version 0.0.0-pr-28984-sha-29839935. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-28984-sha-29839935
Triggered by @JReinhold
Repository storybookjs/storybook
Branch valentin/fix-missing-source-map-warning-second-attempt
Commit 29839935
Datetime Fri Sep 6 14:00:55 UTC 2024 (1725631255)
Workflow run 10739730889

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=28984

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 76.8 MB 76.8 MB 6 B 1.99 0%
initSize 161 MB 161 MB 2.28 kB 1.92 0%
diffSize 84.7 MB 84.7 MB 2.27 kB 0 0%
buildSize 7.52 MB 7.52 MB 0 B 1.73 0%
buildSbAddonsSize 1.62 MB 1.62 MB 0 B 1.73 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 2.34 MB 2.34 MB 0 B 1.73 0%
buildSbPreviewSize 352 kB 352 kB 0 B - 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.51 MB 4.51 MB 0 B 1.73 0%
buildPreviewSize 3.01 MB 3.01 MB 0 B 1.73 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 6.8s 19.9s 13s 1 65.5%
generateTime 20.5s 25.8s 5.3s 1.9 🔺20.7%
initTime 19.3s 21.3s 1.9s 1.86 🔺8.9%
buildTime 14.7s 10.6s -4s -107ms -0.96 -38.6%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 7s 7.7s 702ms 0.95 9%
devManagerResponsive 4.5s 5s 503ms 1.04 9.9%
devManagerHeaderVisible 851ms 1s 232ms 2.27 🔺21.4%
devManagerIndexVisible 895ms 1.1s 228ms 2.23 🔺20.3%
devStoryVisibleUncached 1.4s 1.7s 303ms 1.53 🔺17.4%
devStoryVisible 894ms 1.1s 230ms 2.24 🔺20.5%
devAutodocsVisible 695ms 846ms 151ms 0.87 17.8%
devMDXVisible 792ms 880ms 88ms 1.88 🔺10%
buildManagerHeaderVisible 788ms 793ms 5ms 0.56 0.6%
buildManagerIndexVisible 789ms 831ms 42ms 0.73 5.1%
buildStoryVisible 832ms 830ms -2ms 0.19 -0.2%
buildAutodocsVisible 667ms 717ms 50ms 0.18 7%
buildMDXVisible 687ms 696ms 9ms 0.46 1.3%

Greptile Summary

This PR addresses the issue of missing source map warnings for virtual files in Vite projects by modifying the virtual file naming system and handling in Storybook's Vite builder.

  • Added SB_VIRTUAL_FILES object in virtual-file-names.ts to centralize virtual file paths
  • Implemented getResolvedVirtualModuleId function to add null byte prefix to virtual module IDs
  • Updated webpack-stats-plugin.ts to improve handling of virtual files and maintain backwards compatibility
  • Modified vue-component-meta.ts to exclude virtual modules with null byte prefix in regular expression
  • Refactored code-generator-plugin.ts and external-globals-plugin.ts to use new virtual file naming system

Copy link

nx-cloud bot commented Aug 27, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 06b3056. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@valentinpalkovic valentinpalkovic force-pushed the valentin/fix-missing-source-map-warning-second-attempt branch from 1e20df1 to e6d7ac5 Compare August 27, 2024 18:27
Comment on lines +100 to +120
if (!isUserCode(mod.id)) {
return;
}
mod.importedIds
.concat(mod.dynamicallyImportedIds)
.filter((name) => isUserCode(name))
.forEach((depIdUnsafe) => {
const depId = normalize(depIdUnsafe);
if (!statsMap.has(depId)) {
statsMap.set(depId, createStatsMapModule(depId, [mod.id]));
return;
}
const m = statsMap.get(depId);
if (!m) {
return;
}
m.reasons = (m.reasons ?? [])
.concat(createReasons([mod.id]))
.filter((r) => r.moduleName !== depId);
statsMap.set(depId, m);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

might not be obvious from the diff, but this just changes the flow to use early-return, no actual logic changed.

@JReinhold JReinhold self-assigned this Sep 6, 2024
@JReinhold JReinhold marked this pull request as ready for review September 6, 2024 14:00
@JReinhold
Copy link
Contributor

@IanVS could you try out this canary and ensure it doesn't break your Turbosnap? I've done some things that should hopefully keep the same stats-file output as before, to not signal file-changes.

@JReinhold JReinhold added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Sep 6, 2024
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

!moduleName.match(/node_modules\//)
(moduleName &&
// keep Storybook's virtual files because they import the story files, so they are essential to the module graph
Object.values(SB_VIRTUAL_FILES).includes(getOriginalVirtualModuleId(moduleName))) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using a more descriptive variable name instead of 'moduleName'

Comment on lines +108 to +111
if (!statsMap.has(depId)) {
statsMap.set(depId, createStatsMapModule(depId, [mod.id]));
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider extracting this logic into a separate function for better maintainability

@IanVS
Copy link
Member

IanVS commented Sep 9, 2024

@JReinhold I tested out the canary, and TurboSnap seems to still be working correctly. 🙌

Though I can't speak for the effectiveness of the PR itself, since I don't see the referenced warnings either before or after installing the canary.

@JReinhold
Copy link
Contributor

Thanks for checking @IanVS! ❤️

Though I can't speak for the effectiveness of the PR itself, since I don't see the referenced warnings either before or after installing the canary.

That's okay, we've been able to reproduce it fairly easy, and this seems to solve it.

@JReinhold JReinhold changed the title Builder-Vite: Fix missing source map warning Vite: Fix missing source map warning Sep 9, 2024
@JReinhold JReinhold removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Sep 9, 2024
@JReinhold JReinhold merged commit 5d4791c into next Sep 9, 2024
57 of 58 checks passed
@JReinhold JReinhold deleted the valentin/fix-missing-source-map-warning-second-attempt branch September 9, 2024 20:37
@github-actions github-actions bot mentioned this pull request Sep 9, 2024
9 tasks
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.

[Bug]: /virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files
3 participants