Skip to content

Move Vite rendering to styles twig directive#1447

Open
damsfx wants to merge 1 commit intowintercms:developfrom
damsfx:move-vite-to-styles
Open

Move Vite rendering to styles twig directive#1447
damsfx wants to merge 1 commit intowintercms:developfrom
damsfx:move-vite-to-styles

Conversation

@damsfx
Copy link
Contributor

@damsfx damsfx commented Feb 5, 2026

If the recommendations are followed, the page architecture should be:

<!DOCTYPE html>
<html lang="en">
<head>
    /* Website metas */

    {% styles %}
</head>
<body>
    /* Website content */

    {% scripts %}
</body>
</html>

This avoids FOUC (Flash of Unstyled Content), the browser renders the content progressively, and the experience is better, scripts doesn't block content rendering and all nodes are availables for manipulation.

If a component uses $this->addVite(...) to include the required resources, those resources are rendered in the site's Twig tag {% scripts %}.
In this case, this can cause FOUC issues because the styles are rendered after the entire DOM.

Proposed fix:
The idea is to render Vite's <style /> and <script /> elements from the {% styles %} twig directive:

  • No more FOUC
  • No issues with scripts that could be blocking because the type=“module” attribute is added automatically and acts like the defer attribute.

Summary by CodeRabbit

Release Notes

Refactor

  • Modified asset loading sequences for stylesheets and scripts to streamline the resource compilation pipeline
  • Adjusted asset processing order during page generation for improved resource management and efficiency

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

Walkthrough

These changes relocate Vite asset loading from the ScriptsNode to the StylesNode. The assetsFunction('vite') call is removed from script asset output and added to style asset output, shifting where Vite assets are emitted during template compilation.

Changes

Cohort / File(s) Summary
Asset Loading Relocation
modules/cms/twig/ScriptsNode.php, modules/cms/twig/StylesNode.php
Moved the Vite assets function call from ScriptsNode to StylesNode. ScriptsNode now outputs only JS assets, while StylesNode outputs both CSS and Vite assets in its compilation sequence.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: moving Vite asset rendering from the scripts directive to the styles directive to fix FOUC issues.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LukeTowers
Copy link
Member

@damsfx could you also make the changes to how vite is rendered in the backend?

@damsfx
Copy link
Contributor Author

damsfx commented Feb 6, 2026

@LukeTowers I can't find any use of Vite in the backend module.
Maybe I'm missing something, what are you talking about?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants