Skip to content
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

performance-impl: cant check ampdoc vis hidden while null #36197

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/service/performance-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,14 @@ export class Performance {
* @param {!LayoutShift} entry
*/
tickLayoutShiftScore_(entry) {
if (!this.ampdoc_) {
return;
}

if (this.isVisibilityHidden_()) {
return;
}

const entries = this.layoutShiftEntries_;
if (entries.length > 0) {
const first = entries[0];
Expand Down
16 changes: 16 additions & 0 deletions test/unit/test-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,22 @@ describes.realWin('PeformanceObserver metrics', {amp: true}, (env) => {
return Services.performanceFor(env.win);
}

it('should not throw when layout-shift occurs before core services available', () => {
// Fake the Performance API.
env.win.PerformanceObserver.supportedEntryTypes = ['layout-shift'];
const perf = getPerformance();

// Fake layout-shift that occured before core services registered
performanceObserver.triggerCallback({
getEntries() {
return [
{entryType: 'layout-shift', value: 0.3, hadRecentInput: false},
];
},
Comment on lines +1177 to +1181
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
getEntries() {
return [
{entryType: 'layout-shift', value: 0.3, hadRecentInput: false},
];
},
getEntries: () => [{
entryType: 'layout-shift',
value: 0.3,
hadRecentInput: false,
}],

Copy link
Member Author

@samouri samouri Sep 29, 2021

Choose a reason for hiding this comment

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

just confirming: this is a style nit right? if yes (and CI is green), i'd rather defer b/c time is of the essence

});
perf.coreServicesAvailable();
});

it('when the viewer visibility changes to inactive', () => {
// Specify an Android Chrome user agent.
env.sandbox
Expand Down