Skip to content

Commit

Permalink
🖍 [Story performance] Remove standalone classes (#36127)
Browse files Browse the repository at this point in the history
* Remove standalone classes

* Updated specificity

* Added specificity again

* Remove standalone classes

* Updated specificity

* Added specificity again

* Control element lifecycle with height auto

* Started changing tests to use AmpStory

* Reverted to automatic height

* Remove unused test setup

* Updated comment to make it more clear

* Remove unused rule
  • Loading branch information
mszylkowski committed Oct 8, 2021
1 parent 70fc163 commit 610583b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
5 changes: 2 additions & 3 deletions extensions/amp-story/1.0/amp-story.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ amp-story {
touch-action: manipulation !important;
}

html.i-amphtml-story-standalone,
html.i-amphtml-story-standalone body {
html:root, html:root body {
font-size: calc(2.5 * var(--story-page-vh, 8px));
height: 100% !important;
margin: 0 !important;
Expand Down Expand Up @@ -121,7 +120,7 @@ h6 {
font-size: 0.67rem;
}

html.i-amphtml-story-standalone #i-amphtml-wrapper body {
html:root #i-amphtml-wrapper body {
/** AMP runtime adds a 1px border on iOS iframes, causing the body to be
1px bigger than the viewport. */
border-top: none !important;
Expand Down
2 changes: 0 additions & 2 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,6 @@ export class AmpStory extends AMP.BaseElement {
* @private
*/
initializeStandaloneStory_() {
const html = this.win.document.documentElement;
html.classList.add('i-amphtml-story-standalone');
// Lock body to prevent overflow.
this.lockBody_();
// Standalone CSS affects sizing of the entire page.
Expand Down
10 changes: 5 additions & 5 deletions extensions/amp-story/1.0/test/test-amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {createElementWithAttributes} from '#core/dom';
import {registerServiceBuilder} from '../../../../src/service-helpers';
import {toggleExperiment} from '#experiments';
import {waitFor} from '#testing/test-helper';
import {setImportantStyles} from '#core/dom/style';

// Represents the correct value of KeyboardEvent.which for the Right Arrow
const KEYBOARD_EVENT_WHICH_RIGHT_ARROW = 39;
Expand Down Expand Up @@ -116,6 +117,10 @@ describes.realWin(
});

AmpStory.isBrowserSupported = () => true;

// Fakes the size of amp-story so it's not built/laid out until we call build/layoutCallbacks
// allowing us to mock function calls before the lifecycle callbacks.
setImportantStyles(win.document.documentElement, {'height': 'auto'});
});

afterEach(() => {
Expand All @@ -131,7 +136,6 @@ describes.realWin(

it('should activate the first page when built', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

await story.layoutCallback();
// Getting all the AmpStoryPage objets.
const pageElements = story.element.getElementsByTagName('amp-story-page');
Expand Down Expand Up @@ -161,7 +165,6 @@ describes.realWin(
await createStoryWithPages(2);

const buildShareMenuStub = env.sandbox.stub(story.shareMenu_, 'build');

await story.layoutCallback();
expect(buildShareMenuStub).to.have.been.calledOnce;
});
Expand All @@ -183,7 +186,6 @@ describes.realWin(

it('should pause/resume pages when switching pages', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

await story.layoutCallback();
// Getting all the AmpStoryPage objects.
const pageElements = story.element.getElementsByTagName('amp-story-page');
Expand Down Expand Up @@ -235,7 +237,6 @@ describes.realWin(

it('lock body when amp-story is initialized', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

await story.layoutCallback();
story.lockBody_();
expect(win.document.body.style.getPropertyValue('overflow')).to.be.equal(
Expand All @@ -248,7 +249,6 @@ describes.realWin(

it('checks if pagination buttons exist ', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

await story.layoutCallback();
expect(
story.element.querySelectorAll('.i-amphtml-story-button-container')
Expand Down

0 comments on commit 610583b

Please sign in to comment.