Skip to content

Conversation

@iansan5653
Copy link
Contributor

The stacking order of the avatars inside AvatarStack is controlled via z-index because it is reversed from the DOM order (earlier items display on top). This works fine within the component, but the effects of z-index can easily leak outside the component and cause unexpected bugs wherever any other component overlays AvatarStack. An example of this is https://github.com/github/copilot-productivity/issues/3985 (internal issue link) where the avatars appear on top of a dialog that should cover them.

The stacking order here only matters relative to the other avatars within the same component, so we can easily prevent this type of bug by isolating the z-index effects via a new stacking context. The most explicit way to create a new stacking context is via the isolation property:

The isolation CSS property determines whether an element must create a new stacking context.

This PR simply adds isolation: isolate to the AvatarStack container.

There is prior art for this approach in ButtonGroup; see #2910.

As a followup, it might be worth considering an audit of all uses of z-index within Primer to ensure they are properly isolated. In fact I would even consider an ESLint rule banning the use of z-index so that we have to explicitly override the rule and thus verify that we have considered the side effects + stacking context.

Changelog

New

Changed

Fixed stacking bugs relating to AvatarStack.

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

@iansan5653 iansan5653 requested a review from a team as a code owner February 18, 2025 16:42
@iansan5653 iansan5653 requested a review from camertron February 18, 2025 16:42
@changeset-bot
Copy link

changeset-bot bot commented Feb 18, 2025

🦋 Changeset detected

Latest commit: 03da629

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Feb 18, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Feb 18, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 105.72 KB (-0.02% 🔽)
packages/react/dist/browser.umd.js 106.14 KB (+0.08% 🔺)

@github-actions github-actions bot requested a deployment to storybook-preview-5705 February 18, 2025 16:46 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-5705 February 18, 2025 17:00 Inactive
Copy link
Contributor

@camertron camertron left a comment

Choose a reason for hiding this comment

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

Wow, TIL about stacking contexts 😎 Any way to write tests for this?

@iansan5653 iansan5653 added the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Feb 18, 2025
@github-actions github-actions bot removed the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Feb 18, 2025
@iansan5653 iansan5653 enabled auto-merge February 19, 2025 14:52
@mperrotti
Copy link
Contributor

I have another branch I'm working on that uses mask styles to achieve something similar, and it seems like a slightly nicer approach

@mperrotti
Copy link
Contributor

Here's my alternative: #5714

It's not as straightforward as this solution, but it has some nice benefits. I'll leave it up to the reviewers to decide which direction we want to go.

@iansan5653 iansan5653 added this pull request to the merge queue Feb 26, 2025
Merged via the queue into main with commit 2857a8e Feb 26, 2025
44 checks passed
@iansan5653 iansan5653 deleted the avatarstack-stacking-context branch February 26, 2025 17:32
@primer primer bot mentioned this pull request Feb 26, 2025
hectahertz pushed a commit that referenced this pull request Mar 20, 2025
…acking context (#5705)

* Wrap `AvatarStack` avatars in `isolation: isolate`

* Create strange-pets-stare.md

* Snap!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants