Skip to content

🚀♻️ Extract amp-story-interactive host styles into extension#37051

Closed
alanorozco wants to merge 5 commits intoampproject:mainfrom
alanorozco:interactive-css
Closed

🚀♻️ Extract amp-story-interactive host styles into extension#37051
alanorozco wants to merge 5 commits intoampproject:mainfrom
alanorozco:interactive-css

Conversation

@alanorozco
Copy link
Copy Markdown
Member

@alanorozco alanorozco commented Nov 24, 2021

The provided custom props are not required as part of the larger amp-story-1.0.js bundle. We move them into the amp-story-interactive-1.0.js bundle instead.

This shaves off ~0.55 kb compressed from the larger bundle.

@amp-owners-bot
Copy link
Copy Markdown

amp-owners-bot bot commented Nov 24, 2021

Hey @gmajoulet! These files were changed:

extensions/amp-story-interactive/0.1/amp-story-interactive-abstract.js
extensions/amp-story-interactive/0.1/amp-story-interactive-host.css
extensions/amp-story-interactive/0.1/amp-story-interactive-shadow.css
extensions/amp-story-interactive/0.1/test/test-amp-story-interactive-slider.js
extensions/amp-story/1.0/amp-story.css

Hey @mszylkowski! These files were changed:

extensions/amp-story-interactive/0.1/amp-story-interactive-abstract.js
extensions/amp-story-interactive/0.1/amp-story-interactive-host.css
extensions/amp-story-interactive/0.1/amp-story-interactive-shadow.css
extensions/amp-story-interactive/0.1/test/test-amp-story-interactive-slider.js

Hey @newmuis! These files were changed:

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

* @param {string} cssText
*/
function installHostCssOnce(id, cssRoot, sibling, cssText) {
if (cssRoot.querySelector(`#${escapeCssSelectorIdent(id)}`)) {
Copy link
Copy Markdown
Contributor

@mszylkowski mszylkowski Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would work well if we kept the system style[amp-extension="amp-story-interactive"] to install the styles, why are we doing this instead?

Copy link
Copy Markdown
Member Author

@alanorozco alanorozco Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two options to use the existing style[amp-extension="amp-story-interactive"] system:

  1. By bundling installExtensionsForDoc(), which has a ~0.16 kb impact on amp-story-interactive-1.0.js.

  2. By placing the host CSS in every inherited component, which has a variable impact on runtime performance by overriding styles once for every tag name defined in the extension (10x).

I think the size impact on amp-story-interactive-1.0.js is a more reasonable tradeoff, so I chose to write a function to install once. However, the hand-rolled function is barely smaller, so I'm now using installExtensionsForDoc() instead.

/** @protected {?../../amp-story/1.0/variable-service.AmpStoryVariableService} */
this.variableService_ = null;

installHostCssOnce(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you were going to call this in amp-story-interactive.js before running the registerElements so it's guaranteed to be installed once, instead of trying to install it once per component.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the behavior of instalStylesOrDoc, which verifies whether the style has already been added.

Subjectively, it makes more sense to me to place the call in the abstract implementation instead of AMP.extension(). It's uniform with shadow styles, and it mostly corresponds to the classnames set in the same file.

Copy link
Copy Markdown
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, let's ship it please!!

@mszylkowski
Copy link
Copy Markdown
Contributor

@alanorozco whenever you get the chance, this PR is approved and (after conflict resolution) ready to merge

@gmajoulet
Copy link
Copy Markdown
Contributor

Friendly ping on this, would love to ship it : ))

@stale
Copy link
Copy Markdown

stale bot commented Jan 21, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Inactive for one year or more label Jan 21, 2023
@stale stale bot closed this Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stale Inactive for one year or more

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants