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

[Bug?]: Fragmented and imported css is injected into the body tag and causes html to repaint/shift #1654

Open
2 tasks done
ericarthurc opened this issue Oct 20, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ericarthurc
Copy link

ericarthurc commented Oct 20, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

If you have a component that has its own imported css, and you import the component, the css for that component is built into its own .css file and gets injected into the body tag. This causes issues where the .css file downloads last and that component draws to the screen with no styling at first then flashes and redraws with its style.

image

So that counter button, this is from the basis template, has its own imported .css file. The css for that component injects into the body tag and is delievered after everything is already drawn to the screen. So that button will appear unstyled on inital loading, or renavigations back to the route its on.

Expected behavior 🤔

No response

Steps to reproduce 🕹

Steps:

  1. Create a project
  2. Import a compontent into a route with its own imported css
  3. Inspect the source and dom

Context 🔦

No response

Your environment 🌎

System:
   OS: Windows 121
Binaries:
   Node: 23.0.0
npmPackages:
   solidjs/start: 1.0.9 (latest)
@ericarthurc ericarthurc added the bug Something isn't working label Oct 20, 2024
@ericarthurc ericarthurc changed the title [Bug?]: Fragmented and imported css is injected into the body tag and causes html to repaint [Bug?]: Fragmented and imported css is injected into the body tag and causes html to repaint/shift Oct 20, 2024
@ericarthurc
Copy link
Author

This same behavior happens with module.css files as well.

If I just place everything in a single top level imported .css file, then this isn't an issue.. but that defeates the purpose of modulatrity.

@ericarthurc
Copy link
Author

Also vite cssCodeSplit: false doesn't work. The css is compiled by vite down into a single file, but the generated .html files dont reference the .css file. So the site is just completetly unstyled.

  server: {
    static: true,
  },
  vite: {
    build: {
      cssCodeSplit: false,
    },
  },

@ryansolid
Copy link
Member

I suspect you'd have this problem even if we were manually adding removing style tags from the head.. It is less about location and mostly about timing. Vinxi is handling CSS itself so I can imagine the Vite overloads not working. We need a way to delay rendering until we know the CSS is present I think. We have a lazy route component responsible for pulling stuff in. That's where the check needs to occur I imagine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants