fix: add stable merged refs - #5266
Open
nynexman4464 wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsHeading (@astryxdesign/core) · View in Storybook
Text (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 2 accessibility violation(s) found — 2 serious. Heading - 1 issue(s)
Text - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
nynexman4464
force-pushed
the
fix/stabilize-text-refs
branch
from
August 20, 2026 22:31
a177d69 to
3ceecb4
Compare
nynexman4464
marked this pull request as ready for review
August 20, 2026 23:18
imdreamrunner
approved these changes
Aug 21, 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.
Stack
This is 1 of 3 in GitHub stack #5270:
useMergedRefsand fixText/HeadingReview and land in this order.
Problem
TextandHeadingcurrently build a merged callback ref inline:That creates a different callback ref on every render. React therefore detaches the previous ref and attaches the new one even though the DOM element did not change.
For these components, detaching reaches
useTruncationwithnull. Its cleanup path callssetIsTruncated(false)andsetFullText(''). Those state updates happen during React's commit phase on every parent rerender, including whenmaxLinesis0.User impact
A standalone React 19.2 reproduction has a deliberately temporary consumer loop: while simulated async data is pending, it returns a fresh empty-array fallback; after 100 ms a timer supplies stable data and stops the loop.
<span><Text>The reproduction uses only React, React DOM,
@astryxdesign/core, and esbuild—no framework or application providers. It fails in development and production builds and in every stable Astryx version tested from0.0.15through0.4.5.The consumer still owns its unstable fallback bug. Astryx should not add commit-phase state updates that turn that temporary loop into an immediate fatal error.
Regression from the predecessor implementation
The predecessor text component kept its merged ref stable with
useCallback. Astryx replaced that with an inlinemergeRefs(...)call, losing the stable identity.Fix
This PR adds a public hook:
useMergedRefsmemoizes the combined callback and only changes it when an input ref changes.TextandHeadinguse it as the proof-of-concept and outage fix.The standalone production reproduction was rerun against the packed package:
0.4.5Why the stack is split
This PR stays narrow: it introduces the safe API and fixes the two components implicated by the reproduction. #5267 performs the broad mechanical migration separately. #5269 enables enforcement only after the repository is clean.
Fixes #5264.
Test plan
element → null → elementon rerenderpnpm vitest run packages/core/src/hooks/useMergedRefs.test.tsx packages/core/src/Text/Text.test.tsx packages/core/src/Heading/Heading.test.tsxpnpm -F @astryxdesign/core buildpnpm lint