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: preload paths with different production base path breaks #3061

Closed
wants to merge 3 commits into from

Conversation

rpetersen27
Copy link
Contributor

Description

If a module is imported dynamically, vite detects modules for preloading and replaces the code with the preload helper. This only affects production builds though.

For example:

await import('./test.js')

is replaced with

await __vitePreload(() => import("./test.js"), true ? ["/path/to/other.js"] : void 0)

Modules are preloaded by injecting a link with rel="modulepreload" in the index.html.

As the /path/to/other.js is absolute, this will only work, if the deployed application runs under "/". If the deployed application is under a different path, the preloading will not work.

This fix just adds a dot in front of the preload url such that it will be load relative to the index.html. I don't see, why that should break anything, but I am not 100% sure.

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.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • 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).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@Shinigami92 Shinigami92 added the p3-minor-bug An edge case that only affects very specific usage (priority) label Apr 20, 2021
Shinigami92
Shinigami92 previously approved these changes Apr 20, 2021
@patak-dev
Copy link
Member

@Holorium would you merge main? There was a fix in the test suite that will give us better error logs for Windows.

@rpetersen27
Copy link
Contributor Author

@Holorium would you merge main? There was a fix in the test suite that will give us better error logs for Windows.

I just rebased from main. Pipeline looks good now :)

Shinigami92
Shinigami92 previously approved these changes May 2, 2021
add test-case which uses a base-path
@patak-dev
Copy link
Member

@Holorium I have tested this PR and I don't think we should do the change. At this point, there is an assumption that if you deploy your app to somewhere different than /, then you need to define base properly. Changing this implies a bigger change than what we are discussing in the PR. Could you check if defining a base covers your use case?

@Shinigami92
Copy link
Member

Oh didn't see the comment from patak before

@rpetersen27
Copy link
Contributor Author

@Holorium I have tested this PR and I don't think we should do the change. At this point, there is an assumption that if you deploy your app to somewhere different than /, then you need to define base properly. Changing this implies a bigger change than what we are discussing in the PR. Could you check if defining a base covers your use case?

It actually does not help. We just provide packages and docker containers of our software, but the customers do their on premise installations. Since we only provide parts of the whole software, the customer often use a path based on their branding. So at the time, the code is built, we cannot know the production path and it is unfeasible that the customers build their own packages.

@patak-dev
Copy link
Member

I see, I don't think this use case is covered by Vite at this point. This counts as a feature to me, and I think this is not the only place where changes would be needed. In my opinion, we need input from Evan here.

@gaocheng001
Copy link

404,我该怎么解决?

@sapphi-red sapphi-red added needs rebase and removed p3-minor-bug An edge case that only affects very specific usage (priority) labels Apr 28, 2022
@sapphi-red
Copy link
Member

load relative to the index.html.

IIUC this is covered by base: './' and it was improved by #7644. I'm closing this for now but if 3.0.0-alpha does not cover your use case, please create an issue.

@sapphi-red sapphi-red closed this Jun 14, 2022
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

5 participants