Skip to content

Commit

Permalink
core(full-page-screenshot): do not render zero size rects (#11853)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored and paulirish committed Mar 23, 2021
1 parent 398939e commit 2c5486e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lighthouse-core/gather/gatherers/full-page-screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class FullPageScreenshot extends Gatherer {
for (const [node, id] of lhIdToElements.entries()) {
// @ts-expect-error - getBoundingClientRect put into scope via stringification
const rect = getBoundingClientRect(node);
if (rect.width || rect.height) nodes[id] = rect;
nodes[id] = rect;
}

return nodes;
Expand Down
5 changes: 2 additions & 3 deletions lighthouse-core/report/html/renderer/details-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,8 @@ class DetailsRenderer {

if (!this._fullPageScreenshot) return element;

const rect =
(item.lhId ? this._fullPageScreenshot.nodes[item.lhId] : null) || item.boundingRect;
if (!rect) return element;
const rect = item.lhId && this._fullPageScreenshot.nodes[item.lhId];
if (!rect || rect.width === 0 || rect.height === 0) return element;

const maxThumbnailSize = {width: 147, height: 100};
const elementScreenshot = ElementScreenshotRenderer.render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ describe('DetailsRenderer', () => {
assert.equal(screenshotEl.dataset['rectTop'], '1');
});

it('renders screenshot using item boundingRect if missing in FullPageScreenshot', () => {
it('does not render screenshot if rect missing in FullPageScreenshot', () => {
createRenderer({
fullPageScreenshot: {
screenshot: {
Expand Down Expand Up @@ -462,8 +462,7 @@ describe('DetailsRenderer', () => {
const el = renderer.render(details);
const nodeEl = el.querySelector('.lh-node');
const screenshotEl = nodeEl.querySelector('.lh-element-screenshot');
assert.equal(screenshotEl.dataset['rectLeft'], '0');
assert.equal(screenshotEl.dataset['rectTop'], '0');
expect(screenshotEl).toBeNull();
});
});

Expand Down

0 comments on commit 2c5486e

Please sign in to comment.