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 dev resolution of client modules on Windows #2768

Merged
merged 2 commits into from
Mar 11, 2022
Merged

Conversation

matthewp
Copy link
Contributor

Changes

  • When we create the dynamic script tags for components, in dev we use Vite to get the file path for a module id like astro/client/idle.js.
  • On Windows this was generating file:https:// paths which of course do not work. Fix is to prepend /@fs which is a resolution that Vite understands.

Testing

Tested manually in the example apps only :/

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2022

🦋 Changeset detected

Latest commit: dbd588d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Mar 11, 2022
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Nice catch! Thank you 🙏🏻

Comment on lines 106 to +107
const [, resolvedPath] = await viteServer.moduleGraph.resolveUrl(s);
return resolvedPath;
return '/@fs' + prependForwardSlash(resolvedPath);
Copy link
Member

Choose a reason for hiding this comment

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

Vite's module graph gives us a broken URL? That's so strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that there isn't a function in Vite to give a module ID and return a client-compatible pathname. resolveUrl is the closest there is.

Copy link
Member

Choose a reason for hiding this comment

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

fyi @matthewp and I chatted about this a bit earlier and my integration work might improve this a bit more. The first return value of resolveUrl() is sometimes a more correct URL that we might be able to leverage for windows

Copy link
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

LGTM!

@matthewp matthewp merged commit 49c0d99 into main Mar 11, 2022
@matthewp matthewp deleted the resolve-windows branch March 11, 2022 22:28
@github-actions github-actions bot mentioned this pull request Mar 11, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* Fix dev resolution of client modules on Windows

* Adds a changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants