Infer the wrapped component's ref type in withErrorBoundary - #249
Merged
bvaughn merged 2 commits intoSep 5, 2026
Merged
Conversation
The HOC was parameterized over `Type extends ComponentClass<unknown>`, but no argument mentions `Type`, so it can never be inferred and always falls back to its constraint. Every wrapper therefore came out typed `RefAttributes<Component<unknown, any, any>>`, and passing the ref the wrapped component actually takes stops type-checking: Type 'RefObject<Handle | null>' is not assignable to type 'Ref<Component<unknown, any, any>>' Parameterize over the component instead, so `Type` is inferred from the argument, and read the props and ref off it with `ComponentProps` and `ComponentRef` — which is also what the runtime already forwards. The existing ref test passes a class component, whose instance happens to satisfy `Component<unknown, any, any>`, which is why this went unnoticed. The added test passes a function component that declares a `ref` prop, the React 19 form, and fails to compile without this change. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
|
@Alberto-BaseNet is attempting to deploy a commit to the Brian Vaughn's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Owner
|
Published in react-error-boundary@6.1.5 |
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.
Fixes #248.
withErrorBoundarywas parameterized overType extends ComponentClass<unknown>, but no parameter mentionsType, so it can never be inferred and always falls back to its constraint. Every wrapper came out typed as takingRef<Component<unknown, any, any>>, so passing the ref the wrapped component actually takes fails to compile.This parameterizes over the component instead, so
Typeis inferred from the argument, and reads both sides off it withComponentProps/ComponentRef— matching what the runtime already forwards, and what 6.0.0 declared.The existing ref test passes a class component, whose instance structurally satisfies
Component<unknown, any, any>, which is why this survived #211. The added test passes a function component declaring arefprop — the React 19 form — and does not compile without the change.The constraint needs
anybecause React's ownComponentPropsandComponentRefare constrained byJSXElementConstructor<any>; there is a comment and a narrow eslint exception on that line.Motivation: we hit this upgrading a React 19 CRM frontend off 6.0.0, where it breaks 9 call sites and keeps us pinned.
Co-authored-by: Claude Opus 5 noreply@anthropic.com