fix(core): inline custom CSS into experience HTML head to prevent style flash#8917
Draft
darcyYe wants to merge 5 commits into
Draft
fix(core): inline custom CSS into experience HTML head to prevent style flash#8917darcyYe wants to merge 5 commits into
darcyYe wants to merge 5 commits into
Conversation
COMPARE TO
|
| Name | Diff |
|---|---|
| .changeset/gentle-otters-cheer.md | 📈 +653 Bytes |
| packages/core/src/middleware/koa-experience-ssr.test.ts | 📈 +3.79 KB |
| packages/core/src/middleware/koa-experience-ssr.ts | 📈 +1.92 KB |
a130e69 to
d275df2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When custom CSS is configured for the sign-in experience, the hosted page briefly rendered the built-in styles before the custom CSS applied (a flash of built-in content). Custom CSS was only injected client-side via
react-helmet, which mutates<head>asynchronously after the page had already painted.The experience SSR middleware now inlines the tenant's
customCssinto a<style data-custom-css>element in the served HTML<head>, so custom CSS is part of the cascade on the first paint.The pre-existing client-side react-helmet
<style>(inAppMeta.tsx) is intentionally kept and does not reintroduce the flash: the server-inlined<style>already styles the first paint, and the helmet tag — added later with identical CSS — produces no visible repaint. It is kept because it is the only custom-CSS path for live preview: the server deliberately skips inlining in preview mode (?preview=true), where the console iframe pushes styling live viapostMessage. On the real page it re-asserts the same CSS (a harmless duplicate that also acts as a precedence backstop). Removing it would break live preview without improving the fix.customCssinto<head>before the SSR placeholder substitution, so the</head>match only targets the genuine document head.?preview=true), where the console iframe drives styling live viapostMessage+ react-helmet.</style>sequence in custom CSS so it cannot terminate the<style>element early.window.logtoSsrdata through a newserializeSsrDatahelper that escapes</>/&, preventing a</script>in tenant data (custom CSS or custom content) from breaking out of the inline script.This affects the production/self-hosted (and Cloud) build path; in development the experience is proxied to Vite and the middleware is a no-op.
Testing
Unit tests
Checklist
.changeset