Skip to content

[avatar] Add keepMounted prop to Image part - #5536

Merged
atomiks merged 10 commits into
mui:masterfrom
atomiks:claude/github-issue-5529-6cb9ea
Aug 28, 2026
Merged

atomiks merged 10 commits into
mui:masterfrom
atomiks:claude/github-issue-5529-6cb9ea

Conversation

@atomiks

@atomiks atomiks commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Closes #5529
Closes #2597

<Avatar.Image> determines its loading status by preloading the raw src with a detached new Image(), and mounts the rendered element only once the preload finishes. This breaks composition with image optimizers via render (next/image fetches its transformed URL while the preload downloads the raw original, serialized), and loading="lazy" never takes effect because the preload is always eager.

The new keepMounted prop keeps the image element mounted and derives the loading status from the rendered element's own load/error events, skipping the preload. Fallback coordination, onLoadingStatusChange, and the transition attributes are unchanged. Default behavior without the prop is untouched.

Notes

  • The loading image is not hidden with hidden/display: none: an image without a box never intersects, which would defeat loading="lazy". The docs describe stacking the image and fallback instead.
  • A layout effect checks img.complete so cached images and loads that finish before hydration resolve without a fallback flash. With keepMounted, the image is part of the server HTML and starts loading before hydration, which also addresses [avatar] Fallback flashes for cached images on SSR hydration #4468 for this mode.
  • The internal status starts at idle and is promoted in the layout effect; a non-idle initial value double-fires onLoadingStatusChange('loading') under StrictMode.

@atomiks atomiks added type: new feature Expand the scope of the product to solve a new problem. component: avatar Changes related to the avatar component. labels Aug 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5536
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5536
    

commit: 1a78c12

@code-infra-dashboard

code-infra-dashboard Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+604B(+0.13%) 🔺+209B(+0.14%)

Details of bundle changes

Performance

Total duration: 968.94 ms ▼-318.93 ms(-24.8%) | Renders: 76 (+0) | Paint: 1,580.73 ms ▼-496.24 ms(-23.9%)

Test Duration Renders
Select mount (200 instances) 123.14 ms ▼-61.98 ms(-33.5%) 3 (+0)
Tabs mount (200 instances) 187.57 ms ▼-56.36 ms(-23.1%) 3 (+0)
Menu mount (300 instances) 76.42 ms ▼-37.03 ms(-32.6%) 1 (+0)
Mixed surface mount (app-like density) 61.49 ms ▼-29.95 ms(-32.8%) 5 (+0)
Select open (500 options) 38.67 ms ▼-27.46 ms(-41.5%) 14 (+0)

…and 7 more (+3 within noise) — details


Check out the code infra dashboard for more information about this PR.

@atomiks
atomiks force-pushed the claude/github-issue-5529-6cb9ea branch from 318cf71 to 430ebac Compare August 19, 2026 08:30
@netlify

netlify Bot commented Aug 19, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 318cf71
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a8568d289fc4e0008d14067
😎 Deploy Preview https://deploy-preview-5536--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 1a78c12
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a91652a80c285000808b7fc
😎 Deploy Preview https://deploy-preview-5536--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks marked this pull request as ready for review August 19, 2026 09:25
@atomiks atomiks changed the title [avatar] Add keepMounted prop to Image [avatar] Add keepMounted prop to Image part Aug 19, 2026

@jjenzz jjenzz left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

here's the DX review Codex gave me (see below).

i've been thinking about this a lot. it seems we're only having to increase our API surface because we copied a bad default from Radix (that is, only mounting the image after it's loaded via JS). it isn't ideal that users have to wait for the JS bundle + hydration before the avatar image will even begin to load.

since we're considering a v2, i wonder if we should provide a more correct solution that we can migrate towards. e.g:

  1. expose a new part that has the correct defaults
  2. deprecate Image
  3. update docs to use the new part so new users have the preferred default
  4. remove Image in v2

the only thing i'm struggling with here is what would the part be called 😅 Avatar.Source, Avatar.Graphic, i dno.

thoughts on all this? cos yeah, i realise it's a bit out there.

DX review

The rendered-element loading capability is valid and solves the optimizer and lazy-loading failures. However, keepMounted has no defined v2 destination, and the mounted image creates duplicate accessible content while loading or after an error.

Findings (2)

1. 🔴 High - blocking: keepMounted has no long-term contract

Source: AvatarImage.tsx:47, page.mdx:26

Problem:

The detached preload causes both reported bugs, but the PR preserves it as the default and makes normal rendered-element loading an opt-in. The PR does not establish an independent greenfield need for detached preloading or define which behavior survives in v2. Shipping this boolean now therefore risks making a compatibility mechanism permanent.

User scenario:

A Next.js consumer adds keepMounted now. If v2 makes in-place loading the default, that prop becomes redundant and must be removed. If the prop remains indefinitely, consumers must continue learning two loading models even though the legacy model exists primarily to preserve current DOM and transition behavior.

Decision needed:

This makes rendered-element loading an opt-in even though the detached preload is the source of both linked problems. Before shipping keepMounted, could we decide whether detached preloading remains an intentional v2 behavior?

If both behaviors have independent long-term value, please document the greenfield use for detached preloading and define the v2 default while keeping the prop’s true/false semantics stable. If detached preloading is only compatibility debt, the v2 destination should load in place without this opt-in.

In the latter case, a non-breaking bridge needs a public name and contract that survive unchanged in v2. For example, an additive replacement could become the primary documented part now while the current Avatar.Image declaration receives editor-visible @deprecated guidance naming the replacement and v2 removal. Otherwise, hold the correction for the v2 breaking window. A temporary boolean that users add now and must remember to remove later does not provide a discoverable migration path.

2. 🔴 High - blocking: The image and fallback compete in the accessibility tree

Source: AvatarImage.tsx:143, AvatarFallback.tsx:41, AvatarImage.test.tsx:421

Problem:

With keepMounted, an image remains in the DOM during idle, loading, and error, while the fallback is also rendered. A meaningful image alt and fallback text are therefore both exposed to assistive technology. This persists after an error and also occurs in server HTML before hydration. The suggested CSS is not an accessibility contract; it is optional, and the documented opacity alternative does not remove content from the accessibility tree.

User scenario:

A profile link contains <Avatar.Image alt="Jane Doe" keepMounted> and <Avatar.Fallback>JD</Avatar.Fallback>. While loading or after failure, its accessible name can become “Jane Doe JD” instead of one stable representation.

Requested changes:

Could we make accessibility ownership mutually exclusive without relying on consumer styling? I recommend keeping the mounted image aria-hidden during idle, loading, and error, then exposing it only when it reaches loaded and the fallback unmounts. This preserves the current fallback-first accessibility behavior while still allowing the browser to request the image.

Please add public-contract tests with a meaningful alt for SSR and the loading, loaded, source-change, and error states. Preserve an explicit consumer-provided aria-hidden value through the existing external-prop precedence and test that interaction as well.

Downstream consequences of this recommendation:

  • If this recommendation is adopted, internal aria-hidden management overlaps a consumer-provided value. Address it by preserving external-prop precedence and testing explicit values across loading states.

What is already sound

  • Deriving status from the rendered element removes the raw duplicate request and enables native lazy loading and optimized image components without adding controlled state.
  • The implementation preserves user onLoad and onError handlers and thoroughly tests source changes, hydration, caching, transitions, and native <img> behavior.
  • data-loading and data-error provide useful visual styling hooks for the mounted path.

Verdict

Needs product/API decision - Decide whether detached preloading remains an intentional v2 behavior or is compatibility debt. The accessibility ownership defect also blocks the new mode. CC: @jjenzz


🤖 Review generated with Codex

@atomiks

atomiks commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@jjenzz

I prefer keepMounted over a new component name, because no component name is better than Image. For v2, we should make keepMounted opt-out (i.e. flip the default) or remove it entirely. That seems less costly than a new component & name that diverges from v1 + Radix.

The remaining question is CSS. Unlike detached preloading, keepMounted requires CSS and may need to handle broken-image icons covering the fallback. And lastly, the remaining concern is that the keepMounted name implies only DOM presence, not also loading behavior. A different prop name might be better, but I'm not too fussed.


I’ve applied the Codex aria-hidden finding.

@jjenzz

jjenzz commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

For v2, we should make keepMounted opt-out (i.e. flip the default) or remove it entirely.

my concern was whether adding this prop means:

  • consumer adds keepMounted because it's the approach today
  • we can't mark it @deprecated to pre-warn users of an upcoming change because there would be no alternative to migrate to before v2
  • we remove it in v2 (sudden unexpected breaking change) and they have to update their implementation again

it's still only a single breaking release, but that would force early adopters to edit their implementation twice without warning. a part would mean they're implementing the final contract today, so v2 does not impact them, and we can @deprecate the Image part now to pre-warn users where we're heading.

i definitely agree re: diverging from Radix (just cos Image is a MUCH better name 😅) but i wouldn't say we should let that reason alone prevent us from doing things. we currently diverge everywhere already imo (e.g. Radix uses Dialog.Content not Dialog.Popup), and we can provide a migration skill (or post a PR to Shadcn's) if it's a concern.

if we're not concerned about any of the above tho, then what you're saying could indeed work:

  • add keepMounted now
  • in v2:
    • remove keepMounted and new Image() implementation
    • provide overridable functional positioning styles OOTB

i think that's okay tbh, but just making sure we've considered all of the above first.

the keepMounted name implies only DOM presence, not also loading behavior.

if the changes here make sure the <img /> always has an src attr when mounted (i haven't checked btw, i only reviewed DX) then that's fine i think... mounted+loading is a given.

@jjenzz

jjenzz commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

oh wait, i'm an idiot, we could just do this:

  • add keepMounted now
  • in v2:
    • @deprecate the keepMounted prop
      • remove it from docs
      • remove new Image() implementation
    • provide overridable functional positioning styles OOTB

that way, people using keepMounted={true} will just get a deprecation warning but don't necessarily have to update their code again. is that right? haha thinking aloud. gonna approve on that basis, but correct me if wrong!

only downside is that implies we're heading towards a v3 which we might not want to imply.

@atomiks
atomiks merged commit 0a55012 into mui:master Aug 28, 2026
7 checks passed
@atomiks
atomiks deleted the claude/github-issue-5529-6cb9ea branch August 28, 2026 10:50
arturbien added a commit to whopio/frosted-ui that referenced this pull request Sep 8, 2026
## Summary

Upgrades `@base-ui/react` from `^1.7.0` → `^1.8.0` (latest, published
Sep 4, 2026).

No Frosted UI source changes were required. Validated locally:
- `tsc` (CJS + ESM) ✅
- `eslint` + `stylelint` ✅
- `vitest` — 312/312 tests passing ✅

Sources: [Base UI v1.8.0 release
notes](https://base-ui.com/react/overview/releases/v1-8-0), [GitHub
CHANGELOG](https://github.com/mui/base-ui/blob/master/CHANGELOG.md).

---

## Breaking changes

**Official changelog marks no breaking changes in v1.8.0.**

A few behavioral / API additions consumers (and Frosted UI wrappers)
should be aware of:

| Area | Change |
|---|---|
| Avatar | New `keepMounted` prop on `<Avatar.Image>`
([#5536](mui/base-ui#5536)) — Frosted already
forwards image props, so this is available automatically |
| Combobox | New `createItems` collection API
([#5326](mui/base-ui#5326)) |
| Toast | `update()` can take a function derived from the current toast
([#5464](mui/base-ui#5464),
[#5611](mui/base-ui#5611),
[#5629](mui/base-ui#5629)) |
| Autocomplete / Combobox / Select | Popup can open and be browsed while
`readOnly` ([#5541](mui/base-ui#5541),
[#5531](mui/base-ui#5531)) |
| Navigation Menu | Focus stays on the trigger when opening
([#5479](mui/base-ui#5479)) |
| Field | Neutral validity is published while async validation is in
flight ([#5600](mui/base-ui#5600)) |
| Dialog / Alert Dialog / Popover | Outside clicks from presses that
began before open are ignored
([#5378](mui/base-ui#5378)) |
| Scroll Area | Scrollbars no longer steal focus
([#5430](mui/base-ui#5430)) |

### Frosted UI impact assessment

| Concern | Status |
|---|---|
| Compile / typecheck against 1.8.0 | Passes with no source edits |
| Existing `DialogRootActions` / `AlertDialogRootActions` imports |
Still exported |
| `useRender` / `mergeProps` | Unchanged public surface |
| Toast manager `update()` | Still compatible; functional updates are
additive |
| Combobox `useFilter` re-export | Still present |

---

## Full v1.8.0 changelog (from
[upstream](https://base-ui.com/react/overview/releases/v1-8-0))

_Sep 4, 2026_

### General changes

- Fix label association when a control unregisters (#5456)
- Reduce animation completion work (#5535)
- Fix prop and ref merging for lazy render elements (#5562)
- Fix roving focus when items are added or removed (#5447)
- Fix hover and focus interaction issues (#5037)
- Improve trigger mount performance (#5426)
- Fix disabled anchor tracking on scroll (#5478)
- Fix transform origin for start/end alignment (#5015)
- Remove duplicate options key from arrow middleware (#5606)
- Register passive touch listeners (#5572)

### Alert Dialog

- Ignore outside clicks from presses that began before open (#5378)

### Autocomplete

- Render groups with the rowgroup role in grid mode (#5564)
- Allow opening and browsing the popup while `readOnly` (#5541)
- Move `aria-orientation` to the role owners (#5551)
- Hide group labels and scrollbars from the accessibility tree (#5598)

### Avatar

- Add `keepMounted` prop to `<Avatar.Image>` (#5536)

### Checkbox

- Fix stale and duplicated control IDs (#5457)
- Fix controlled blur validation and stale filled state (#5563)

### Checkbox Group

- Fix stale and duplicated control IDs (#5457)

### Combobox

- Fix applying `data-readonly` to `<Combobox.Trigger>` (#5418)
- Add `createItems` collection API (#5326)
- Fix cancellation when preserving the filter after selection (#5362)
- Render groups with the rowgroup role in grid mode (#5564)
- Allow opening and browsing the popup while `readOnly` (#5541)
- Move `aria-orientation` to the role owners (#5551)
- Fix record item label lookup reading from `Object.prototype` (#5518)
- Anchor multiple selection to the first selected item with a linear
lookup (#5573, #5613)
- Hide group labels and scrollbars from the accessibility tree (#5598)

### Dialog

- Ignore outside clicks from presses that began before open (#5378)

### Drawer

- Ignore swipes without an attributed direction when using snap points
(#5477)
- Respect canceled snap point dismissal (#5571)
- Ignore the page scroller when starting a swipe (#5567)

### Field

- Fix custom validity ownership and validation lifecycle (#5449)
- Sync controlled value changes with field state (#5460)
- Fix stale and duplicated control IDs (#5457)
- Validate once on Enter inside a Form (#5459)
- Publish neutral validity while async validation is in flight (#5600)
- Fix controlled blur validation and stale filled state (#5563)

### Form

- Fix `clearErrors` dropping updates when multiple fields change at once
(#5446)

### Menu

- Play the enter transition for an initially open submenu (#4383)
- Move `aria-orientation` to the role owners (#5551)
- Hide group labels and scrollbars from the accessibility tree (#5598)

### Menubar

- Fix menubar accessibility tree to satisfy `aria-required-children`
(#5058)

### Navigation Menu

- Fix pointer-events lock when sweeping quickly across a trigger (#5454)
- Keep focus on trigger when opening (#5479)
- Add disabled data attribute to `<NavigationMenu.Trigger>` (#5521)

### Number Field

- Stop incrementing when disabled during press-and-hold (#5435)
- Prevent scrubbing on horizontal wheel events (#5463)
- Preserve native and consumer-controlled selection when focusing the
input (#5578, #5619)

### Popover

- Ignore outside clicks from presses that began before open (#5378)
- Fix detached trigger store migration (#5442)

### Scroll Area

- Hide group labels and scrollbars from the accessibility tree (#5598)
- Prevent scrollbars from stealing focus (#5430)

### Select

- Move `aria-orientation` to the role owners (#5551)
- Anchor multiple selection to the first selected item with a linear
lookup (#5573, #5613)
- Hide group labels and scrollbars from the accessibility tree (#5598)
- Fix the root ID being ignored inside a Field (#5461)
- Remove redundant size check in `<Select.Positioner>` (#5469)
- Allow opening and browsing the popup while `readOnly` (#5531)
- Fix record item label lookup reading from `Object.prototype` (#5518)

### Slider

- Prevent update loops from unstable refs (#5441)

### Switch

- Fix controlled blur validation and stale filled state (#5563)

### Tabs

- Prevent update loops from unstable refs (#5441)
- Consider 3D transforms when positioning the indicator (#4852)

### Toast

- Allow functional toast updates derived from the current toast (#5464,
#5611, #5629)

### Tooltip

- Respect trigger delay with zero provider delay (#5444)

---

## Test plan

- [x] Bump `@base-ui/react` to `^1.8.0` and refresh lockfile
- [x] `pnpm --filter=frosted-ui exec tsc --project tsconfig-esm.json
--noEmit`
- [x] `pnpm --filter=frosted-ui build:js` (CJS + ESM)
- [x] `pnpm --filter=frosted-ui lint`
- [x] `pnpm --filter=frosted-ui test` (312 tests)
- [x] CI green on this PR
- [ ] Spot-check Storybook surfaces that wrap Base UI heavily (Combobox,
Select, Dialog, Menu, Toast, Field) if desired before merge


Made with [Cursor](https://cursor.com)

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: avatar Changes related to the avatar component. type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Avatar] Derive Image loading status from the rendered element (make render work with next/image) [avatar] Support lazy-loading

2 participants