Closed erwinheldy closed 4 months ago
Is this documented anywhere @erwinheldy ?
It's a Vite thing: https://vitejs.dev/guide/assets.html#importing-asset-as-string, we have a few part of the docs either directly recommending the pattern, or linking to their docs. We also recommend it once in a while to people in support.
It's a common pattern for component library documentation, so they can show both the component and its source code without duplication
Yes, indeed, it's a Vite thing as mentioned by @Princesseuh.
I found out that if you try to render the imported Astro component with ?raw
the output is the source string.
Given the following example:
---
import { RawComponent } from './components/Component.astro?raw'
---
<RawComponent /> {/* this will output `component.astro` source code */}
Therefore, if this is the expected behavior, it is worth changing the type definition of *.astro?raw
in astro/client
.
@erwinheldy With that in mind you can utilize slots or newly added Container API to render the component and get the source string.
I think it is just a matter of the plugin that turns .astro source into a component function not ignoring the ?raw modifier.
Maybe at some point it started parsing it instead of just checking the suffix.
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
The Astro component import behavior has changed regarding the
?raw
suffix, which previously treated the imported component as astring
but now results in afunction
type. This inconsistency is illustrated by the following code snippet:Previously, the
typeof Button
would returnstring
, but now it returnsfunction
, which is unexpected behavior and may impact existing code relying on the previous string type behavior. I forgot which version still resulted in a string.What's the expected result?
The expected result is that
typeof Button
should returnstring
when importing an Astro component with the?raw
suffix, as it did in previous versions where this behavior was consistent.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-4mfaty?file=src%2Fpages%2Findex.astro
Participation