-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 Windows dev script proxying #2052
Conversation
|
✔️ Deploy Preview for astro-www ready! 🔨 Explore the source changes: 2ee36e0 🔍 Inspect the deploy log: https://app.netlify.com/sites/astro-www/deploys/61a577acaf48e10007b6ce74 😎 Browse the preview: https://deploy-preview-2052--astro-www.netlify.app |
✔️ Deploy Preview for astro-docs-2 ready! 🔨 Explore the source changes: 2ee36e0 🔍 Inspect the deploy log: https://app.netlify.com/sites/astro-docs-2/deploys/61a577ace559090007d92ba3 😎 Browse the preview: https://deploy-preview-2052--astro-docs-2.netlify.app |
94bf944
to
cbe484f
Compare
6c9e964
to
3f717b4
Compare
3f717b4
to
2ee36e0
Compare
@@ -266,7 +266,8 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO | |||
|
|||
// run transformIndexHtml() in dev to run Vite dev transformations | |||
if (mode === 'development') { | |||
html = await viteServer.transformIndexHtml(viteifyURL(filePath), html, pathname); | |||
const relativeURL = filePath.href.replace(astroConfig.projectRoot.href, '/'); | |||
html = await viteServer.transformIndexHtml(relativeURL, html, pathname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big change 1: use project-relative URLs to generate the script proxies. Here’s the difference:
- <script type="module" src="/:/Users/astro/code/my-project/src/pages/index.astro?html&proxy=0.js">
+ <script type="module" src="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/index.astro?html&proxy=0.js">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the /:/
is because C:/
isn’t the start of a browser-compatible pathname
// mark the entrypoint as scanned to avoid an infinite loop | ||
scanned.add(moduleName.id); | ||
scanned.add(moduleName.url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big change 2: use url
instead of id
in Vite’s module graph. Here’s the difference between the two, according to Vite:
ID
- Linux/Mac:
/Users/astro/code/my-project/src/pages/index.astro
✅ valid in module graph & in browser - Windows:
C:/Users/astro/code/my-project/src/pages/index.astro
❌ valid in module graph but not valid in browser (the original bug)
URL
- Linux/Mac:
/@fs/Users/astro/code/my-project/src/pages/index.astro
✅ valid in module graph & in browser - Windows:
/@fs/C:/Users/astro/code/my-project/src/pages/index.astro
✅ valid in module graph & in browser
This PR uses url
so that the same value can be placed in the browser and resolved.
*/ | ||
export function viteifyURL(filePath: URL): string { | ||
return slash(fileURLToPath(filePath)); | ||
return `/@fs${filePath.pathname}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updates the viteifyURL
function to use module graph url
over id
if (match[1].includes('Research.js')) { | ||
componentUrl = match[1]; | ||
break; | ||
describe('dev', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No build tests changed; only added “dev” tests
} else { | ||
this.viteServer.moduleGraph.invalidateAll(); | ||
} | ||
await this.viteServer.moduleGraph.invalidateAll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last change: when something threw an error, we were doing too much work to only invalidate some modules, possibly missing many in the process. If something has erred, just invalidate everything 🤷🏻.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! These fixes to handle Windows filenames and the test updates look great to me 👍
Added one note on a skipped test, but I'm not 100% sure on whether the test is useful or not and don't think that should block merging in these fixes
https://docs.astro.build/reference/api-reference/#importmeta` | ||
); | ||
}); | ||
// TODO: is this still a relevant test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it seems like this should still be a useful test?
Test #2 checks that data-reactroot
isn't added to the test page's <Hello />
component since it isn't using client hydration. It looks like this test would be making sure that data-reactroot
is still used on the hydrated <Research />
component
What I'm not actually sure on is whether data-reactroot
is still used to flag hydrated react components. If yes, I think this and test #2 should be useful, if no I think both tests aren't helpful anymore (since test #2 would always get undefined regardless of how hydration was used)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this test has been skipped since the move to Vite/0.21
. @natemoo-re what should this test look for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe data-reactroot
is required for hydrated components still. If this test is broken it might be a symptom of a bug we need to fix. Happy to spin off into a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Yeah if that could be investigated separately (ideally testing dev and build) that would be good. This test needs to be updated, but I wasn’t sure exactly how (and is unrelated to this PR).
* Add tests for script proxying * Fix Windows script proxying withastro#2053
Changes
Fixes #2053. In dev, Windows was getting bad URLs for script proxying. This behavior only existed in dev, not build, so dev tests needed to be added that we didn’t have before.
Testing
Tests added that didn’t exist before.
Docs
No docs changes.