Skip to content

fix(atomic-wind): add fallback size to icon SVG - #3179

Open
faisalahammad wants to merge 1 commit into
Codeinwp:masterfrom
faisalahammad:fix/3129-atomic-wind-icon-default-size
Open

faisalahammad wants to merge 1 commit into
Codeinwp:masterfrom
faisalahammad:fix/3129-atomic-wind-icon-default-size

Conversation

@faisalahammad

Copy link
Copy Markdown

Closes #3129.

Summary

The built-in Atomic Wind icon SVG was rendered with a viewBox but no width/height. Until the Tailwind utility CSS arrives, the browser paints it at the default replaced-element size (measured around 1264x1264 unstyled), then snaps down once the utilities apply. On cache misses (every page save clears the cached CSS) and on archive views the CSS only lands in the footer, so the flash shows up on normal page loads.

This adds width="1em" height="1em" presentation attributes to the built-in icon SVG as a fallback. They are the weakest sizing signal in the cascade: the size-* utilities are generated with !important and still override them, so final rendered sizes are unchanged. The custom SVG branch is untouched and keeps its own dimensions.

Screenshots

No steady-state visual change. The fix only affects the first paint before the utility CSS loads.


Test instructions

  1. Build and start the env: npm ci && composer install && npm run build && npm run env:start (site at http://localhost:8888, admin/password).
  2. Create a page with an Atomic Wind pattern that contains icons (or insert the Icon block directly), publish it.
  3. View the page source: the icon markup now has width="1em" height="1em" next to the viewBox.
  4. In DevTools set network throttling to Slow 4G, update the page in the editor (this clears the cached CSS), then reload the frontend. Icons should be about text size from the first paint instead of flashing huge. Also check an archive or search view with the same icons, those always use the footer CSS path.
  5. With CSS loaded, compare icon sizes against master: identical. Then enable Custom SVG on the icon block and paste an SVG with width="32" height="32": it still renders at 32x32 and keeps its own attributes, no 1em added.

Automated: full PHPUnit suite passes (819 tests, 3577 assertions), including two new tests covering the fallback attributes and the custom SVG branch. npm run test:unit, phpcs and phpstan are clean.

Known trade-off: a hand-written single-axis utility on an icon (e.g. w-8 with no height utility) now renders 1em tall instead of the aspect-derived square it had before. All shipped patterns use size-* (both axes), and the base CSS alternative proposed in the issue has the same behavior.


Checklist before the final review

  • Included E2E or unit tests for the changes in this PR.
  • Visual elements are not affected by independent changes.
  • It is at least compatible with the minimum WordPress version.
  • It loads additional script in frontend only if it is required.
  • Does not impact the Core Web Vitals.
  • In case of deprecation, old blocks are safely migrated. (No deprecation involved.)
  • It is usable in Widgets and FSE.
  • Copy/Paste is working if the attributes are modified. (No block attributes changed.)
  • PR is following the best practices

The built-in icon SVG had no width or height, so it painted at the
browser default size until the Tailwind utilities arrived. On cache
misses and non-singular views the CSS only lands in the footer, so
icons flashed huge before snapping to their real size.

Add width="1em" height="1em" presentation attributes as a fallback.
Size utilities are generated with !important and still override the
attributes, so final rendered sizes are unchanged. Custom SVGs keep
their own dimensions.

Fixes Codeinwp#3129
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Atomic Wind icons flash at wrong size on page load (Tailwind CSS generated client-side)

1 participant