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: js fallback sourcemap content should be using original content #15135

Merged
merged 3 commits into from
Nov 24, 2023

Conversation

sapphi-red
Copy link
Member

Description

Follow up to #14247.

fixes #14247 (comment)

I tested this change with VSCode, Chrome, Firefox.

Additional context


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.

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: sourcemap Sourcemap support labels Nov 24, 2023
@sapphi-red
Copy link
Member Author

/ecosystem-ci run

@@ -27,6 +27,7 @@ export interface SendOptions {
cacheControl?: string
headers?: OutgoingHttpHeaders
map?: SourceMap | { mappings: '' } | null
originalContent?: string
Copy link
Member

Choose a reason for hiding this comment

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

Should this be () => string in case it doesn't end up being used to save the file read?

Copy link
Member Author

@sapphi-red sapphi-red Nov 24, 2023

Choose a reason for hiding this comment

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

send function is a sync function and is part of the public API. Therefore originalContent cannot be () => Promise<string>. To satisfy () => string, we need to change fsp.readFile to fs.readFileSync in getOriginalContent. But I guess async is better for perf.

Copy link
Member

Choose a reason for hiding this comment

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

It would be good to find a way to avoid the perf regression. In a full .ts code base, there will now be a new read for each transformed file that won't be used, no? I think at one point we could have an internal send function that is async (everywhere internal usage could be changed to await), but given that it may be complex, for now we could add a guard at https://github.com/vitejs/vite/pull/15135/files#diff-6d94d6934079a4f09596acc9d3f3d38ea426c6f8e98cd766567335d42679ca7cR208, with a comment? Even if it is redundant, we at least save a few reads?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, OK. I noticed I was missing type === 'js'.

Copy link
Member Author

Choose a reason for hiding this comment

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

In a full .ts code base, there will now be a new read for each transformed file that won't be used, no?

Just to make it clear, this won't happen. .ts files will always have source maps, so map == null is always false.

@Soarex16
Copy link

Thank you for such a quick response!

I also checked in the WebStorm debugger and now everything works fine.

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on a8b6843: Open

suite result latest scheduled
analogjs success success
astro success success
histoire failure failure
ladle success success
laravel failure failure
marko success success
nuxt failure failure
nx success success
previewjs success success
qwik success success
rakkas success success
sveltekit failure failure
unocss success success
vike success success
vite-plugin-pwa success success
vite-plugin-react success success
vite-plugin-react-pages success success
vite-plugin-react-swc success success
vite-plugin-svelte success success
vite-plugin-vue success success
vite-setup-catalogue success success
vitepress success success
vitest success success

@patak-dev patak-dev merged commit 227d56d into vitejs:main Nov 24, 2023
10 checks passed
@sapphi-red sapphi-red deleted the fix/js-sourcemap-content branch November 25, 2023 00:36
cpojer added a commit to cpojer/vite that referenced this pull request Nov 29, 2023
patak-dev pushed a commit that referenced this pull request Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: sourcemap Sourcemap support p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants