Skip to content

🚀 [Story performance] Fix CLS caused from AMP runtime CSS showing story before amp-story.css#37990

Merged
mszylkowski merged 23 commits intoampproject:mainfrom
mszylkowski:clsFromRuntimeCSS
Apr 1, 2022
Merged

🚀 [Story performance] Fix CLS caused from AMP runtime CSS showing story before amp-story.css#37990
mszylkowski merged 23 commits intoampproject:mainfrom
mszylkowski:clsFromRuntimeCSS

Conversation

@mszylkowski
Copy link
Copy Markdown
Contributor

@mszylkowski mszylkowski commented Mar 31, 2022

On origin ampshared.css shows the document when v0.js is installed, but in many cases this happens in a different frame than amp-story.css being installed, meaning that for a split second the layout shows with just the ampshared.css styles and without amp-story.css. When this happens, the active page can change the size (especially for inline elements that take space) which causes CLS=1.

TL;DR: If amp-story.css is not present, we don't want to show the story due to possible CLS. On cached docs the CSS is inlined so this won't affect anything, but on origin this prevents a flash of unstyled story.

Somewhat reverts back #37345 but shows the story earlier (CSS installation is earlier than layoutCallback is completed).

dist/v0/amp-story-0.1.mjs: Δ -0.05KB
dist/v0/amp-story-1.0.mjs: Δ -0.05KB
dist/v0/amp-story-0.1.js: Δ -0.04KB
dist/v0/amp-story-1.0.js: Δ -0.04KB
dist/v0.js: Δ -0.06KB

@gmajoulet gmajoulet marked this pull request as ready for review March 31, 2022 18:42
@amp-owners-bot amp-owners-bot bot requested a review from alanorozco March 31, 2022 18:42
@amp-owners-bot
Copy link
Copy Markdown

Hey @gmajoulet, @newmuis! These files were changed:

extensions/amp-story/1.0/amp-story.css

1 similar comment
@amp-owners-bot
Copy link
Copy Markdown

Hey @gmajoulet, @newmuis! These files were changed:

extensions/amp-story/1.0/amp-story.css

@gmajoulet gmajoulet requested review from jridgewell and removed request for alanorozco March 31, 2022 18:42
@mszylkowski mszylkowski self-assigned this Mar 31, 2022
@mszylkowski
Copy link
Copy Markdown
Contributor Author

There's been a regression of some unrelated unit tests that this PR caught, I'm fixing them on #37994 and then merging this PR (these unit tests are blocking this merge)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants