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

Virtual module ids with query parameters that end in .astro throw errors #11230

Closed
1 task done
BryceRussell opened this issue Jun 10, 2024 · 3 comments · Fixed by #11240
Closed
1 task done

Virtual module ids with query parameters that end in .astro throw errors #11230

BryceRussell opened this issue Jun 10, 2024 · 3 comments · Fixed by #11240
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@BryceRussell
Copy link
Member

BryceRussell commented Jun 10, 2024

Astro Info

Astro                    v4.10.1
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             astro-test-invalid-transform

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

The transform hook inside the vite plugin astro:build matches module ids that are not Astro files but contain paths to Astro files inside query parameters, for example:

virtual:test?importer=%2Fhome%2Fprojects%2Fgithub-vdjlmf%2Fsrc%2Fpages%2Findex.astro

This issue occurs because Astro uses .endsWith to check for Astro files

if (!id.endsWith('.astro') || parsedId.query.astro) {

- if (!id.endsWith('.astro') || parsedId.query.astro) {
-   return
- } 
+ if (!parsedId.filename.endsWith('.astro')) {
+   return
+ }
+ if (parsedId.query.astro) {
+   return
+ }

One workaround for this is to add an empty query parameter as a suffix:

virtual:test?importer=%2Fhome%2Fprojects%2Fgithub-vdjlmf%2Fsrc%2Fpages%2Findex.astro&end

What's the expected result?

Astro does not attempt to transform virtual module's that have .astro paths inside query parameters

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-vdjlmf?file=astro.config.mjs,src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jun 10, 2024
@matthewp
Copy link
Contributor

@matthewp matthewp added the - P3: minor bug An edge case that only affects very specific usage (priority) label Jun 11, 2024
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Jun 11, 2024
@BryceRussell
Copy link
Member Author

BryceRussell commented Jun 11, 2024

If this fix uses createFilter, are the include and exclude options meant to be configurable from the Astro config? If not, it may be simpler and faster to skip the filter function and directly check that filename ends with .astro using regex or endsWith.

@matthewp
Copy link
Contributor

No, not intending to change any public API at all. Could just be a regular regexp, yeah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants