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

Duplicate stylesheet injection in production build #5834

Closed
1 task
kiley-mitti opened this issue Jan 11, 2023 · 12 comments · Fixed by #6034
Closed
1 task

Duplicate stylesheet injection in production build #5834

kiley-mitti opened this issue Jan 11, 2023 · 12 comments · Fixed by #6034
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@kiley-mitti
Copy link

kiley-mitti commented Jan 11, 2023

What version of astro are you using?

1.9.1

Are you using an SSR adapter? If so, which one?

No

What package manager are you using?

npm

What operating system are you using?

Mac, Linux

Describe the Bug

When using a layout which extends another layout, CSS stylesheets get injected twice in the production build of the site. This occurs on any page using the extended layout.

The first injection occurs in the <head> of the page.

The second injection occurs at the beginning of the <body> of the page.

Thank you so much for your attention to this issue! If you need any further information let me know.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-2ugymh-oqddw9

UPDATE (1/19/23): We've found that this also extends to injectScript as well, so built a second example to account for that too. Hopefully this is useful to you!

https://stackblitz.com/edit/github-2ugymh-e6stgx

Participation

  • I am willing to submit a pull request for this issue.
@natemoo-re natemoo-re added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Jan 11, 2023
@nicholasray
Copy link

I think this issue and #5715 might be related

@matthewp
Copy link
Contributor

@nicholasray yes it likely is. I'm planning on taking a look soon.

@z336
Copy link

z336 commented Jan 24, 2023

Adding a +1 to this bug, I'm seeing link and script tags injected twice on pages using one of the layouts. Thanks!

What version of astro are you using?

1.9.0

Are you using an SSR adapter? If so, which one?

No

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

Stylesheet and script tags are being injected into the body with one layout but not both. The layout it's happening to is PageLayout.astro in my repo.

Link to Minimal Reproducible Example

https://astro-docs-prototype.netlify.app/
https://github.com/z336/astro-docs-prototype

@matthewp
Copy link
Contributor

Thanks for the repro! I'll be working on this soon.

@marcfilleul
Copy link

marcfilleul commented Jan 28, 2023

I had this issue with nested layouts so I reverted back to a unique layout for now.

Now I have the same issue in a component with a so it looks like the imported js and css are duplicated as soon as we use a (in a layout or in a component).

Duplication occurs in dev and in prod.

Edit: My component is a Svelte component so it's not limited to Astro layouts or components.

@matthewp
Copy link
Contributor

I have a fix for this, just working out some details to avoid breaking some corner case layouts. Should have this in a patch next week.

@z336
Copy link

z336 commented Jan 31, 2023

No more duplicate script/link tags for me, but on one of my layouts (the opposite this time) it's injecting them into the body. Can see that behavior on this page: https://astro-docs-prototype.netlify.app/docs/en/tutorial/a-tutorial/

I updated to 2.0.4 and this time it's my ArticleLayout.astro pages (so, flipped from my original comment above).

@nicholasray
Copy link

nicholasray commented Jan 31, 2023

fwiw, I also experienced the flash of unstyled content with 2.0.4. I reverted back to 2.0.2 as a result

@z336
Copy link

z336 commented Jan 31, 2023

I'm only see the tags injected into the body on pages that have MDX components, so it looks like it may have more to do with the MDX integration than layouts at this point. I'll check for any other filed issues and create a new one if need be.

@matthewp
Copy link
Contributor

matthewp commented Feb 1, 2023

Thanks, ping me if you file a new issue.

@z336
Copy link

z336 commented Feb 1, 2023

@matthewp Hi, thank you for the attention on this. I added my details here: #6057 (comment)

@jamaluddinrumi
Copy link

jamaluddinrumi commented Jul 7, 2023

duplicate css injections   fouc

i experienced duplicate css injections & flash of unstyled content

i remove @astrojs/prefetch and it's resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants