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
✨ Version lock CSS #17562
✨ Version lock CSS #17562
Conversation
This ensures that when an AMP doc is Server Side Rendered (by inlining the v0.css or any extension's CSS into the doc), the inlined styles are exactly what the JS expects. This eliminates the possibility of version skew for pages that use cached v0.js but inlined CSS.
src/style-installer.js
Outdated
@@ -131,6 +131,7 @@ export function installStylesLegacy( | |||
* @return {!Element} | |||
*/ | |||
function insertStyleElement(cssRoot, cssText, isRuntimeCss, ext) { | |||
cssText = cssText.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to trim?
Because if we do we should make it so that we don't have to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, AMP Cache doesn't.
But, I'm concerned with pub SSR generating:
<style>
/* whitespace *//* CSS */
/* whitespace */</style>
If they do that, I didn't want to override the CSS and cause a reparse. And if we allow it to remain, we would need to strip the value when installing CSS into child windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider that invalid for SSR. @honeybadgerdontcare
Let's avoid the trimming here. It may increase memory usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the trimming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, we can assist with pub SSR generation. Filed b/112736946 and b/112737536.
src/style-installer.js
Outdated
@@ -146,6 +147,9 @@ function insertStyleElement(cssRoot, cssText, isRuntimeCss, ext) { | |||
if (key) { | |||
const existing = getExistingStyleElement(cssRoot, styleMap, key); | |||
if (existing) { | |||
if (existing.textContent.trim() !== cssText) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
* Version lock CSS This ensures that when an AMP doc is Server Side Rendered (by inlining the v0.css or any extension's CSS into the doc), the inlined styles are exactly what the JS expects. This eliminates the possibility of version skew for pages that use cached v0.js but inlined CSS. * Tests * Don't trim * Don't trim
This ensures that when an AMP doc is Server Side Rendered (by inlining
the v0.css or any extension's CSS into the doc), the inlined styles are
exactly what the JS expects. This eliminates the possibility of version
skew for pages that use cached v0.js but inlined CSS.