-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Rendering content collection entries through a loop with imported astro components causes broken scripts and styles #6672
Comments
I would like to check it. |
This is because script/style propagation is dependent on the template being static. We examine the template and see that there are components which contains styles and then wait on that portion before sending the I anticipated this problem when working on head propagation but couldn't think of a good solution. I think some explicit API is probably needed here. For example if there was a |
const { Content } = await entries[0].render();
const { Content: Content2 } = await entries[1].render();
---
<Content />
<Content2 /> It sounds a little weird. |
I wouldn't say the issue is solved. It simply adds wrong html markup with script and style tags. Yes, the browser displays the expected output, but the final generated html is completely wrong and unacceptable (Reproduction: https://stackblitz.com/edit/github-b1xdf7-mcrjxh. |
I tried a lot, but didn't find the best way to solve it So I think it can only be used as a temporary solution. |
Reopening since this introduced a separate bug, and causes unexpectedly broken Markup as noted by @putnik-projects |
This issue has been reported several times, and is currently being tracked in #7761. |
What version of
astro
are you using?2.1.7
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Mac
What browser are you using?
Chrome
Describe the Bug
The new Content Collection API lets you import mdx files and render their content anywhere using the
.render()
method, and only imports those components and their styles and scripts when they're used on a page. This works perfectly when generating routes from content - on each page an entry, its scripts and styles are executed and bundled. But when I try to render multiple entries on one page through a loop, scripts and styles don't work.Everything works when explicitly tell astro which components to render (see reproduction):
I want to render my mdx components with imported nested astro components through an array, as this is the only way to use astro components and prevent bundling of unused scripts and styles (#6328)
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-b1xdf7-ptottr?file=src%2Fcomponents%2FRenderEntry.astro,src%2Fpages%2Findex.astro,src%2Fpages%2Ffinal.astro
Participation
The text was updated successfully, but these errors were encountered: