question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SVGs and child nodes referenced from local SVG sprite count towards "Avoid an excessive DOM size"

See original GitHub issue

Provide the steps to reproduce

  1. Run LH on https://andro4all.com/

What is the current behavior?

SVGs pointing to a local svg are adding nodes like they were the whole svg.

<svg class="mrf-Icon mrf-Icon--s">
	<use xlink:href="#mrf-Icon--bullet"></use>
</svg>

becomes

<svg class="mrf-Icon mrf-Icon--s">
	<use xlink:href="#mrf-Icon--bullet">
		<!-- shadow root -->
		<svg id="mrf-Icon--bullet" viewBox="0 0 24 24">
			<circle cx="12.5" cy="12.5" r="4.5"></circle>
		</svg>
	</use>
</svg>

So, lighthouse evaluates this nodes too.

What is the expected behavior?

This svgs are pointing to a shared sprite SVG, so, lighthouse doesn’t have to add the nodes inside the use tag. This rule penalizes reusing svgs instead of adding a new svg all the time.

Replacing this SVGs for dummy nodes in this page, for instance, like

<span class="mrf-Icon mrf-Icon--s">
	<span xlink:href="#mrf-Icon--bullet"></span>
</span>

decreases the total by 376 nodes.

Environment Information

  • Affected Channels: Devtools
  • Lighthouse version: Lighthouse 4.0.0-beta
  • Node.js version: macOS

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:12

github_iconTop GitHub Comments

1reaction
patrickhulcecommented, Dec 2, 2020

Just curious, will you count as dom objects actual pixels…?

Lighthouse counts the same number of pixels as the number of times snark has solved a GitHub issue 😉

Unless there’s evidence someone can point to that the original concern is not valid for SVGs with <use>, Lighthouse won’t be treating them any differently. I’m skeptical that rendering additional copies of an SVG is a completely free operation.

The goal of the audit is to capture the render/style/layout costs of many nodes. IIUC, using <use href> doesn’t necessarily eliminate the cost of extra DOM bookkeeping/rendering of having an extra copy of the SVG while replacing the SVGs with dummy spans does eliminate the associated costs.

Also keep in mind, this audit has absolutely no impact on the performance score and is just a diagnostic pointing to a potential issue. As with everything in the performance section, if the metrics are good, the score is good, skip the diagnostics. If the metrics are bad, then the diagnostics like this are a good place to start investigating.

1reaction
PerfectedAppcommented, Dec 2, 2020

Just curious, will you count as dom objects actual pixels…?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid an excessive DOM size (Inline SVG or SVG file tag)?
It becomes an issue when the DOM has over a total of 1500 nodes, a greater Depth of 32 nodes and a parent...
Read more >
Too Many SVGs Clogging Up Your Markup? Try `use`.
This works and renders just fine, but results in a bloated DOM tree, where each shape is represented as separate nodes. Displaying all...
Read more >
Automatic Translation of Interactive SVGs to a Multithread ...
Abstract—. The dominant markup language for Web visualizations—Scalable Vector Graphics (SVG)—is comparatively easy to learn, and is open,.
Read more >
Using SVG and Vue.js: A complete guide - LogRocket Blog
js. From the simple question of how best to load SVG files into your templates, to handling animations and accessibility, there are plenty...
Read more >
How your favourite UI libraries manage their icons
The a2k-icon component cloned these SVGs into the DOM via use . ... custom icons, simply pass through your SVG node as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found