Repository navigation
fix: resolve the react-hooks/refs and set-state-in-effect warnings - #3323
Merged
Merged
Conversation
interactivellama
force-pushed
the
fix/react-hooks-refs
branch
from
November 16, 2026 08:07
6214a12 to
7230487
Compare
interactivellama
force-pushed
the
fix/react-hooks-refs
branch
from
November 17, 2026 02:22
7230487 to
b11cd11
Compare
interactivellama
force-pushed
the
fix/react-hooks-refs
branch
from
November 17, 2026 02:47
b11cd11 to
9588c7c
Compare
interactivellama
force-pushed
the
fix/react-hooks-refs
branch
from
November 17, 2026 21:54
0da3925 to
4a18345
Compare
interactivellama
force-pushed
the
fix/react-hooks-refs
branch
from
November 17, 2026 22:45
4a18345 to
12b7197
Compare
interactivellama
force-pushed
the
fix/react-hooks-refs
branch
from
November 18, 2026 23:06
12b7197 to
21f940a
Compare
interactivellama
force-pushed
the
fix/react-hooks-refs
branch
from
November 19, 2026 04:41
21f940a to
7d4919e
Compare
The refs rule follows ref reads through functions called during render, so Combobox and Tooltip still reported after the id change: - Combobox built input onChange handlers with withInputOnChange(...) in each sub-render. They are now two memoized handlers: handleInnerInputChange, and handleInnerInputChangeWhileUnselected for the single-selection variants that ignore typing once an option is selected. - Combobox called getCustomPopoverProps(body) in renderPopover and read the merged props' id. The props are now memoized as customPopoverProps, and the popover id comes from the popover prop. - Tooltip passed the trigger props (and their handlers) to renderTrigger from its own render. The trigger slot now renders through a small TooltipTrigger component. Rendered output and handler behaviour are unchanged.
handleCloseRef was assigned during render so the open-dropdown registration could call the latest handleClose. It now uses useLatestRef, which updates the ref in an insertion effect. Its only reader is another dropdown's open handler, which runs after commit.
Prettier output only: wrap the keyboardNavigate declaration and drop the trailing blank lines.
…gger componentContext captured triggerRef.current in a useMemo, so the value was frozen when the memo ran: null on the first render, and only refreshed when handleClick changed identity. keyboardNavigate's "Enter/Down on the closed trigger also clicks it" branch therefore ran or not depending on timing. Pressing Enter on a closed trigger called onClick 0 times the first time; the second time it called onClick once and onRequestOpen twice, because handleClick's stale getIsOpen opened the menu again after toggleOpen had. componentContext now exposes getTrigger(), read at keydown time, and its handleClick only reports onClick: toggleOpen has already opened the menu. Each keyboard open from the trigger now reports onClick, onRequestOpen and onOpen exactly once. 0.10.x (componentContext was the component instance, so the trigger was always current) also called onClick once, but went through handleOpen twice. The new test presses Enter on the closed trigger over two open/close rounds and fails without this change.
… width in state The width measured on mount was kept only in initialStageWidthRef and read during render for the item width. It is now state, set in the mount effect next to stageWidth, so both updates batch into one render. That change made the effect that copied the panel offset into translateX state report set-state-in-effect. translateX is now derived during render from the width and currentPanel, which also drops a render per panel change. Until the stage is measured it keeps the old off-screen value (-1000000), so first paint is unchanged.
Portal kept its container node in portalNodeRef next to an isMounted flag, and render read the ref to call createPortal. The attached node is now state: the mount effect sets it where it used to set isMounted, and render portals into it. The effects still use the ref. It is the same single extra render as before, and under StrictMode the double mount still removes the first node before creating the second. The setState in the mount effect still reports set-state-in-effect; the next commit documents why it stays.
The portal node has to be appended to its parent before the children mount, because Dialog measures its target in its own effects and child effects run before parent effects. Creating the node in render would put a DOM side effect in render, and creating it later would mount the children into a detached node. This is the "sync with an external system" case the rule allows but cannot detect, so it gets an inline disable with the reason, as docs/codebase-overview.md asks.
…ffect An effect kept activeSelectedOption and its index inside selection after a controlled parent shrank it (#3211). The clamp ran after commit, so for one render no pill had tabindex=0. The index is now clamped while rendering, and the active pill is read from selection by index, so it is correct on the first render. The separate activeSelectedOption state and its setters are gone; SelectedListbox only reads the index. The new test empties a controlled selection and fills it again, and checks the first pill is tabbable. It passes before and after this change and guards the refactor, as does the existing #3211 test.
…ons change An effect moved the highlight (activeOptionIndex) to the highlighted option's new position when options changed, or cleared it when the option was gone. Until it ran, aria-activedescendant could point at the wrong option or at one that no longer existed. The check now runs during render and only sets state when the stored index is stale, so it settles after one extra render and never commits a stale index. It compares the option's position rather than the getOptions identity: optionsSearchEntity and optionsAddItem default to new arrays on each render, so getOptions changes every render. The new test reorders the options under a highlighted option, then removes it, and checks aria-activedescendant follows and then clears.
With the react-hooks/refs and set-state-in-effect warnings fixed, lint is at 0 warnings, so npm run lint now runs with --max-warnings=0. The ROADMAP P3 backlog entry is closed and its status row updated, and AGENTS.md and the PR template no longer describe warnings as an accepted backlog.
A popover that mounted open was never positioned, so it kept Dialog's fallback `pointer-events: none` and nothing inside it could be clicked (the ColorPicker "Menu Open" story, `walkthrough-on-anchor`). Root cause: the container ref callback depended on an `inputRendered` state that nothing read. Its first call set that state, which recreated the callback, so React detached and re-attached the trigger ref in the next commit. Dialog asks for its target element in that same commit, got null, and skipped `createPopper`. Removing the unused state keeps the callback stable.
Nothing called onRequestClose with { trigger: 'clickOutside' }. The
rewrite dropped the react-onclickoutside HOC, and the unused
handleClickOutside was later deleted, so a controlling parent (such as
ColorPicker) never learned about outside clicks. Popover now listens with
useClickOutside while open, treating its container and any portal
content carrying ignore-click-<id> as inside.
The stories and the doc-site example left isOpen to ColorPicker, so they did not show the controlled model: the parent receives onRequestOpen and onRequestClose and sets isOpen. Menu Open now starts with a controlled isOpen instead of defaultIsOpen. onChange no longer passes the React event to action(), which threw while serializing it and stopped OK before its close request.
… Filter popover A popover in a portal (position="overflowBoundaryElement", as Filter uses) never received focus on open, so Escape, which the popover handles on its own keydown, did nothing until the user clicked inside it. Portal called onOpen in the effect that creates its node, before the children had rendered into it; Dialog's handleOpen then found no dialog content and skipped moving focus. Portal now calls onOpen in the commit after the node exists, when the children are in the document.
The stories' footer buttons (Cancel, Save, OK, Back, Next, and so on) had no onClick, so only Escape and the close button closed the modal. ModalWithTrigger now passes its close handler to a footer render function, and each story's buttons call it.
…xes controlled Checkbox is controlled, and the example passed neither `checked` nor `onChange`, so clicking a checkbox did nothing. Keep each cell's checkbox state and update it from `data.checked`.
12c615e moved the trigger measurement into a layout effect keyed on open state and align, so a trigger that resized while the tooltip stayed open kept its old size and the nubbin sat off-centre. The old in-render measurement ran every render; the layout effect now does too, and its updater keeps the same state when the size is unchanged, so it settles.
The anchored nubbin hides the SLDS nubbin with a `#<id>:after` rule. An id passed in that is not a CSS identifier (one that starts with a digit, or holds a space or a quote) made the rule invalid, so the browser dropped it and both nubbins showed. The rule now uses an `[id="…"]` attribute selector, which matches any id.
interactivellama
force-pushed
the
fix/react-hooks-refs
branch
from
November 21, 2026 00:03
b702c20 to
404e0d8
Compare
interactivellama
marked this pull request as ready for review
November 21, 2026 00:26
Niznikr
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the v11 merge train, stack 1 "clean CI": react-hooks-refs → deprecated-dom-apis (#3327) → deprecated-prop lint (#3311) → private exports. ci-warnings (#3322) has merged, so this PR now targets
masterand merges first.Additional description
This fixes the 32
react-hooks/refsand 3react-hooks/set-state-in-effectwarnings and removes the lint cap from the previous PR, so lint warnings are back to the tracked backlog.useRef(generateId())and read during render (22: color-picker, combobox, date-picker, tooltip)useId(). A passedidstill takes precedence. Since React 19.2,useIdreturns ids such as_R_1_, which are valid CSS identifiershandleCloseRefduring render, and memoizedtriggerRef.currentuseLatestRef. It also reports oneonClickper keyboard open from the triggerDialog fixes found while testing the stories
react-onclickoutside, soonRequestClosenever fired for an outside clickuseClickOutsideand callsonRequestClose(event, { trigger: 'clickOutside' }). When controlled, it only requests the close and stays open until the parent closes itinputRenderedstate recreated the container callback ref on mount, so the trigger ref was detached while Dialog asked for its targetonOpenbefore its children mounted, so Dialog couldn't move focus insideonOpenfrom an effect after the portal node renders#<id>:afterrule is invalid for an id that isn't a CSS identifier (leading digit, space, quote)[id="…"]attribute selectorisOpen, andaction('onChange')(event, data)threw on the circular React event before the close request__examples__/default.jsxownisOpenand close fromonRequestOpen/onRequestClose. The story logs onlydataisOpenand close from the footer buttons. Prettier formatting is in a separatestyle(modal)commitcheckedwith no handlerEach fix has a regression test where the behavior is observable, for example:
getBoundingClientRectonClickcountidreaching the DOM for Combobox, DatePicker and TooltipSnapshots
17 story snapshots change their generated ids from
slds-snapshot-id-Nto_R_…_. These are stable: each story renders as its ownrenderToStaticMarkuproot, so its ids depend only on its own tree. Full and filteredtest:snapshotsruns both pass with--update=none.Breaking changes
This PR has no breaking API changes. Behavior changes to be aware of:
Popovernow callsonRequestClosewith{ trigger: 'clickOutside' }, as 0.10.x did.onOpenfires once the children have mounted, one render later than before._R_1_instead ofslds-…. Passidif you need a fixed one.CONTRIBUTOR checklist (do not remove)
Please complete for every pull request.
Green gate — all of these must pass locally (CI runs the same):
npm run lintpasses with 0 errors (npm run lint:fixto auto-fix). Warnings are the tracked gradual-migration backlog; do not add new errors.npm run typecheckis clean (tsc --noEmit).npm test -- --runpasses — this runs both Vitest projects (jsdomunit+ real-browserbrowser) and the story HTML snapshots. If you changed rendered markup on purpose, update snapshots withnpm test -- --run -uand review the diff.npm run buildsucceeds (type-check + Vite library build +.d.ts+ entry shims).Behavior & docs:
components/button/__tests__). New props and bug fixes should get a regression test. Tests that genuinely need a real browser (focus traversal, layout/measurement, canvas) go in a*.browser.test.jsxfile (thebrowserproject); everything else is jsdom.npm run storybook→ http://localhost:6007/. Confirm the story actually renders and behaves (deprecated Storyshots/Karma are gone; there is no separate browser-tests server).content/visualPickerFigure, render props likerenderItem,iconprops,events), not assumptions — a common source of "component looks broken" reports has been stories authored against the wrong API. Cross-check againstcomponents/<name>/__examples__..d.ts(they're generated by the build); JS consumers rely on them via editor type-acquisition.REVIEWER checklist (do not remove)
CIworkflow: lint, typecheck, test, build). Chromatic visual review, if configured, has been checked.components/__tests__/__snapshots__/story-snapshots.test.jsx.snap).@salesforce/design-system-react/components/<name>and nested paths resolve for ESM, CJS, and types). Removing/renaming a public component or export is a breaking change →feat!:/BREAKING CHANGE:and a major version bump.