openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Refactor: Extract pre-hydration web component styles from head.html into a dedicated CSS file

Open Arnav-0206 opened this issue 8 months ago • 4 comments

Description

There is a TODO in templates/site/head.html indicating that pre-hydration web component styles (e.g., for ol-read-more and ol-chip) should be moved from an inline <style> block into a dedicated CSS file.

Currently, these styles are embedded directly in the template, which makes the file harder to maintain and prevents effective browser caching.

This change would improve maintainability and separation of concerns by moving these styles into a standalone stylesheet.


Proposed Solution

  • Extract the inline CSS from head.html
  • Move it into a dedicated CSS file (e.g., in the static CSS directory)
  • Link the stylesheet in head.html
  • Ensure styles still load correctly before hydration

Benefits

  • Cleaner and more readable template files
  • Better separation of concerns (HTML vs CSS)
  • Improved caching and performance

Arnav-0206 avatar Mar 27 '26 10:03 Arnav-0206

Hey, I’m a first-time contributor and would like to work on this. I’ll start working on the fix and share a PR soon.

Arnav-0206 avatar Mar 27 '26 10:03 Arnav-0206

Im also intrested and i wish to work on this

eshanthh avatar Mar 27 '26 20:03 eshanthh

Hi @lokesh,

I worked on this refactor as well and have submitted a PR (#12211).

If you think I should make any changes or follow other conventions, just let me know. Also, we can even collaborate if you like.

Thanks!

Arnav-0206 avatar Mar 28 '26 07:03 Arnav-0206

Hey @Arnav-0206 , I'm going to close this as we aren't ready to tackle this issue. We need to do a bit more thinking about how we want to address the layout shift caused by web components pre-hydration. It might entail SSR, automated css extraction, or a solution like the one proposed, but we need to do a bit more research on all options first.

lokesh avatar Apr 01 '26 02:04 lokesh