Skip to content

fix: catch unstable merged refs - #5429

Merged
nynexman4464 merged 1 commit into
mainfrom
fix/detect-hoisted-merge-refs
Aug 24, 2026
Merged

nynexman4464 merged 1 commit into
mainfrom
fix/detect-hoisted-merge-refs

Conversation

@nynexman4464

@nynexman4464 nynexman4464 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • rename the rule to @astryx/no-unstable-merged-refs now that it covers more than inline expressions
  • follow a local const initialized by the imported mergeRefs into a JSX ref
  • keep the analysis deliberately one hop and scope-aware, including import aliases, TypeScript wrappers, conditional refs, and shadowed or outer-scope bindings
  • migrate the eight hoisted callbacks the rule finds across Avatar, Button, SideNav, TabList, and TopNav
  • memoize Avatar's name callback so useMergedRefs can remain stable without losing status-label updates

This is a separate follow-up to #5269 and is based directly on the commit that merged it to main.

Why

Assigning mergeRefs(...) to a local constant does not stabilize it: the component still creates a new callback on every render, so React detaches and reattaches the ref during unrelated updates. The original rule only walked upward from a mergeRefs call to a JSX ref, so a variable declaration and later ref={mergedRef} lived in disconnected AST subtrees and escaped detection.

The extension resolves only same-file, same-function variable bindings whose initializer is a direct call to the imported mergeRefs. It intentionally does not chase assignments, alias chains, imported values, or stable module-scope refs.

Fail-first evidence

  • Rule regression case: failed with Should have 1 error but had 0 for a local const mergedRef = mergeRefs(...) used as a JSX ref.
  • Avatar and Button regression tests: both failed before the fix because an unrelated rerender called the consumer ref twice (null, then the same element).
  • Running the extended rule on the prerequisite branch reported eight hoisted declarations, including Avatar and Button; all eight were migrated.

Test plan

  • pnpm lint:strict (0 errors; pre-existing warnings only)
  • pnpm test (569 files, 11,821 tests on the functional change; the rule-only rename is also covered by CI)
  • pnpm build
  • focused component tests for Avatar, Button, SideNav, TabList, and TopNav (6 files, 400 tests)
  • focused no-unstable-merged-refs RuleTester suite (16 tests)

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 24, 2026
@vercel

vercel Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 24, 2026 3:51pm

Request Review

@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Avatar (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 719 -
Complexity N/A Very High (85) -
Button (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 535 -
Complexity N/A Very High (63) -
SideNav (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1970 -
Complexity N/A Very High (186) -
TabList (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1167 -
Complexity N/A Very High (90) -
TopNav (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 2092 -
Complexity N/A Very High (150) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@nynexman4464 nynexman4464 changed the title fix: catch hoisted mergeRefs callbacks fix: catch unstable merged refs Aug 24, 2026
@nynexman4464
nynexman4464 force-pushed the fix/detect-hoisted-merge-refs branch from b6f4847 to abb4212 Compare August 24, 2026 15:47
@nynexman4464
nynexman4464 marked this pull request as ready for review August 24, 2026 15:47
@nynexman4464
nynexman4464 merged commit 7a9ff42 into main Aug 24, 2026
21 of 22 checks passed
@nynexman4464
nynexman4464 deleted the fix/detect-hoisted-merge-refs branch August 24, 2026 16:02
cixzhang added a commit that referenced this pull request Aug 24, 2026
cixzhang added a commit that referenced this pull request Aug 24, 2026
* docs: consolidate + credit changesets for v0.5.0

- add the PR reference to all 45 pending changesets, in prose rather than
  on the handle line (a bare @handle line is what check-changesets requires)
- credit @rubyycheung, not @RubyCheung, for the Dialog responsive work in
  #5352; those are two different real GitHub accounts
- add two missing changesets for merged work that changes published
  behaviour: #4605 (Breadcrumbs current-item weight) and #5259 (CLI unified
  search includes integration components)

* docs: add the PR reference to the PowerSearch operator-menu changeset

#5242 landed while this PR was open.

* docs: add the PR reference to the merged-refs stability changeset

#5429 landed while this PR was open.

This branch was successfully deployed

1 active deployment
Preview — abb42127 Deployed Aug 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant