Coder Social home page Coder Social logo

Comments (5)

blittle avatar blittle commented on August 16, 2024

Maybe we could provide an easy way to hook into and extend the streaming lifecycle?

from hydrogen-v1.

colindunn109 avatar colindunn109 commented on August 16, 2024

We had a chat in our shared slack thread but thought that it would make more sense to move the discussion here.

Curious on timeline on when this could be fixed/if it could be fixed. Our team would love to be able to rip out Tailwind to use CSS modules as it fits our use case pretty well and is a pattern our team likes.

Happy to help debug in anyways that we can - but want to make sure I don't go too deep into CSS Modules if this is a larger scale fix.

Also, if we were to not use CSS Modules, do you guys have a recommendation of CSS framework to use that isn't Tailwind?

edit:
I'll note that we looked into the following per your guys recommendation:
https://github.com/unocss/unocss
https://github.com/callstack/linaria
https://github.com/4Catalyzer/astroturf
https://github.com/seek-oss/vanilla-extract

And had similar troubles to CSS Modules.

Would overall be great to be able to do a css-in-js/css modules approach as it aligns with our existing system and would making porting our components a lot easier than retooling to use Tailwind. I think Tailwind is great for people spinning up net new components for a new web app, but less for a team thats built out a ton of their components already.

Let me know how I can help!

from hydrogen-v1.

blittle avatar blittle commented on August 16, 2024

I did some research into this. It looks like the right way to do it is to utilize the ssrManifest to know what CSS modules are necessary for a given route. For some reason the manifest in hydrogen is missing all of the route dependencies. Maybe it is due to the routes being loaded by globEager? @frandiox do you have any ideas?

from hydrogen-v1.

frandiox avatar frandiox commented on August 16, 2024

@blittle Unfortunately, I don't think an ssrManifest would do the trick here. This manifest is supposed to be generated during client build, and this build is not even exploring server components (so CSS modules wouldn't be discovered).

I think this issue is more complex than what it looks like:

  • As mentioned, when building the client (yarn build:client), server components are not explored so CSS files here won't be generated.
  • When building the server (yarn build:server), these CSS modules are finally discovered but since it's an SSR build, files with the styles are not emitted (we'd need to instruct Vite somehow to do this). If they were, they'd be placed in dist/server, which then we'd need to move to dist/client/assets.
  • Even if we get the style files emitted, we need to include a reference to them in our SSR output (at runtime) for each page. Therefore, we would need to generate some information that we can read in our stream/render logic and include a <link href="/path/to/styles"> tag (or inline the style in the HTML).
  • We also need to cover the case where we are navigating using only RSC. One of the lines in the flight response should be this style tag.

This seems to be something that needs an official integration with RSC.

For now, I think the easiest workaround is just including CSS modules only in client components. E.g. instead of writing import {myStyle} from './style.module.css'; .... <div className={myStyle}> directly in a server component, you extract that into <MyDivWithStyle> component in a *.client.jsx file.

We might be able to implement a Vite plugin to support this out of the box but perhaps we should sync with Sebastian first.

from hydrogen-v1.

blittle avatar blittle commented on August 16, 2024

@frandiox yikes, that does sound a lot more complex :(

Afaik CSS modules works fine in client components, except for the flash of unstyled content. I'm reluctant to accept that as a proper solution, so I think it is better to just say it isn't supported at the moment.

from hydrogen-v1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.