Skip to content

finding(react): useETagCache re-allocates its config object on every render inside useRef #6817

Description

@claude

Noticed while implementing objectui#6797 (the react-hooks/refs write on this
same hook). Not repaired there: it is a different defect class, nothing in that
card's gate family covers it, and the repair there did not require touching this
line.

What

packages/react/src/hooks/useETagCache.ts:211 (measured on a77a00c2c):

constconfigRef=useRef({ enabled, storage, storagePrefix, maxEntries, ttl });

useRef's argument is evaluated on every render, and every result after the
first is discarded — useRef only reads it to seed the initial value. So this
allocates a fresh five-key object per render of every component using the hook,
forever, to no effect.

Why it is worth a card rather than a shrug

It is the same pattern PR objectui#6796 named and repaired in
useSchemaPersistenceuseRef(createLocalStorageAdapter()), which invoked a
factory on every render and kept only the first result. That one had to change
because clearing its warning required it; this one does not, which is exactly
why it survives and why it needs its own card rather than a rider.

The cost here is far smaller than objectui#6796's case: an object literal, not a
factory call, and the discarded object holds no resources. No user-visible
impact is claimed
— this is an observation, filed for triage to grade.

Not measured

Whether any consumer renders this hook hot enough for the allocation to matter.
useETagCache currently has zero in-repo consumers (packages/react/src/hooks/index.ts:35
exports it; nothing else in the repo calls it), so any impact is on published
consumers only.

Dedupe

/search/issues answers 403 for this seat, so this went through the REST list
endpoint plus a local grep: 254 open issues collected, zero hits for
useETagCache, useRef, per-render, or allocation other than objectui#6797
itself. Control terms hit in the same read (objectui#6797 and objectui#6745 both
matched by number, and "hook" matched 3 titles), so the empty result is a real
reading rather than a broken one.


Generated by Claude Code

Metadata

Metadata

Assignees

Labels

domain:uiobjectui ui stream: fix lands on the published library or apps — objectui execution seatpriority:p2

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions