Skip to content

[EuiCard] Memoize theme styles - #10175

Open
vianmangal wants to merge 4 commits into
elastic:mainfrom
vianmangal:fix/eui-card-memoized-styles-10152
Open

vianmangal wants to merge 4 commits into
elastic:mainfrom
vianmangal:fix/eui-card-memoized-styles-10152

Conversation

@vianmangal

Copy link
Copy Markdown
Contributor

Summary

Fixes #10152.

Use useEuiMemoizedStyles for the theme-only style generators in EuiCard, EuiCardSelect, and EuiCheckableCard. Extract the image, icon, and beta badge padding rules into a separate dynamic helper so cards with different paddingSize values can share the theme styles safely. Call the beta badge hook unconditionally so badges can be added or removed during rerenders.

Add regression coverage for sharing theme styles across instances and rerenders, independent image/icon/badge padding at every nonzero padding size, and toggling beta badges. Update the two affected snapshots for the composed Emotion class labels.

No changelog, as requested by the issue.

API Changes

None.

Screenshots

No intended visual changes. Padding behavior is checked with CSS assertions; the snapshot changes only reflect composed Emotion class labels.

Impact Assessment

  • Breaking changes
  • Visual changes
  • Test impact — generated Emotion class names for card images and beta badges change; two snapshots updated.
  • Hard to integrate

Impact level: 🟢 Low

Release Readiness

Documentation, Figma, migration guide, and adoption plan are not applicable to this internal performance refactor.

Validation

From packages/eui:

  • React 18: card suites plus style_memoization.test.tsx — 70 tests passed; 50 snapshots passed.
  • React 17: the same suites — 69 tests passed, one React 18-only test skipped; 50 snapshots passed.
  • tsc --noEmit --incremental false --preserveSymlinks — passed. --preserveSymlinks is needed because this checkout reuses an existing installation with the identical Yarn lockfile through local dependency symlinks.
  • ESLint on the changed source/test files — zero errors, four existing warnings.
  • Stylelint on card.styles.ts, Prettier on the changed source/test files, and git diff --check — passed.

QA instructions for reviewer

  1. Run yarn test-unit --runInBand src/components/card src/services/theme/style_memoization.test.tsx.
  2. Repeat with --react-version=17 before the Jest arguments.
  3. In the Card examples, compare image/icon cards and beta badges at different padding sizes, including none; confirm alignment and badge positioning remain consistent.

Checklist before marking Ready for Review

  • Filled out applicable sections above
  • Tests: added regression tests and updated affected Jest snapshots
  • QA: browser, accessibility, CodeSandbox, and Kibana checks
  • Visual regression tests (not run locally)
  • Changelog: omitted as explicitly requested by [Emotion] Memoize EuiCard styles #10152

Reviewer checklist

  • Approved Impact Assessment
  • Approved Release Readiness

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

👋 Since this is a community submitted pull request, a Buildkite build has not been started automatically. Would an Elastic organization member please verify the contents of this pull request and kick off a build manually?

@github-actions github-actions Bot added the community contribution (Don't delete - used for automation) label Oct 5, 2026
@vianmangal
vianmangal marked this pull request as ready for review November 12, 2026 21:34
@vianmangal
vianmangal requested a review from a team as a code owner November 12, 2026 21:34
Copilot AI balanced review requested due to automatic review settings November 12, 2026 21:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@weronikaolejniczak weronikaolejniczak added the skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) label Nov 17, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>

@weronikaolejniczak weronikaolejniczak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for contributing, @vianmangal! 🎉

There are 2 snapshots we'd have to update in Kibana so I pushed a prep commit to this PR.

@elastic-vault-github-plugin-prod

Copy link
Copy Markdown

📷 2 visual difference(s) found

Look at the visual diff below. If everything is expected, run Approve visual changes to update baselines, re-run the job or make appropriate fixes.

See the visual regression testing wiki for more information.

Expand to review

euisuperdatepicker (2 differences)

StoryDiff %BeforeAfterDiff
custom time zone display desktop 0.05%
custom time zone display mobile 0.19%

Co-authored-by: Cursor <cursoragent@cursor.com>
@weronikaolejniczak

Copy link
Copy Markdown
Contributor

buildkite test this

@weronikaolejniczak weronikaolejniczak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Turns out the PR was out-of-date with main that already memoized this part. But it's worth memoizing 2 more styles here.

@weronikaolejniczak
weronikaolejniczak enabled auto-merge (squash) November 17, 2026 12:40
auto-merge was automatically disabled November 17, 2026 12:40

Head branch was pushed to by a user without write access

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

History

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

History

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community contribution (Don't delete - used for automation) skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Emotion] Memoize EuiCard styles

3 participants