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

feat(optimizer): show a friendly warning with 404 instead of 504 outdated optimize dep #16080

Conversation

sapphi-red
Copy link
Member

Description

Respond with 404 instead of 504 Outdated optimize dep for files that in dep directory but not handled by Vite.

I set entryNames and chunkNames so that the files Vite expects all have the same prefix __vite-. If a file that doesn't have that prefix is imported, it means it's something that we don't support. In that case, Vite now responds with 404 instead of 504, and shows a warning that a dependency might be incompatible.

close #13506

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 p2-nice-to-have Not breaking anything but nice to have (priority) feat: deps optimizer Esbuild Dependencies Optimization labels Mar 2, 2024
Copy link

stackblitz bot commented Mar 2, 2024

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

@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

@sapphi-red
Copy link
Member Author

plugin-svelte fail is expected. The snapshot needs to be updated because the path of the optimized files are changed.

@patak-dev patak-dev added this to the 5.2 milestone Mar 5, 2024
@bluwy
Copy link
Member

bluwy commented Mar 12, 2024

I'm not quite sure about this change since the optimized dep directory now looks like .vite/deps/__vite-@foo_bar.js instead of .vite/deps/@foo_bar.js. Mainly only from the stylistic point of view 😅

During esbuild prebundling, we should have a metafile of all output files. Could we match against that instead? .vite/_metadata.json seems to have the list of all file names too.

@sapphi-red
Copy link
Member Author

During esbuild prebundling, we should have a metafile of all output files. Could we match against that instead? .vite/_metadata.json seems to have the list of all file names too.

To do that, we'll have to save the previous _metadata.jsons so that we can know that the request is an outdated one.

We can make the prefix (__vite-) shorter as long as it's sufficiently unique.

@bluwy
Copy link
Member

bluwy commented Mar 13, 2024

To do that, we'll have to save the previous _metadata.jsons so that we can know that the request is an outdated one.

I'm not sure I understand. Isn't it already handled here?

If I change the check to

          if (metadata.depInfoList.some((dep) => dep.file === file)){
            // Outdated non-entry points (CHUNK), loaded after a rerun
            throwOutdatedRequest(id)
          }
          throwFileNotFoundInOptimizedDep(id)

It seems to work (test passing).

@sapphi-red
Copy link
Member Author

Ah, that's right. I'll update to do it like that.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

This looks great!

@patak-dev patak-dev merged commit 7ee4261 into vitejs:main Mar 13, 2024
10 checks passed
@sapphi-red sapphi-red deleted the feat/throw-friendly-error-for-incompatible-deps branch March 14, 2024 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: deps optimizer Esbuild Dependencies Optimization p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vite returns 504 Outdated Optimize Dep for non-existing resource
3 participants