Repository navigation
[useButton] Capture component stack for nativeButton error message - #3861
Conversation
commit: |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
75b4dca to
9cf4584
Compare
Greptile OverviewGreptile SummaryEnhances the developer experience by capturing React component stack traces in
Confidence Score: 5/5
Important Files Changed
|
4bad03e to
3100199
Compare
| const ownerStackMessage = SafeReact.captureOwnerStack?.() || ''; | ||
| error( | ||
| 'A component that acts as a button was not rendered as a native <button>, which does not match the default. Ensure that the element passed to the `render` prop of the component is a real <button>, or set the `nativeButton` prop on the component to `false`.', | ||
| `A component that acts as a button was not rendered as a native <button>, which does not match the default. Ensure that the element passed to the \`render\` prop of the component is a real <button>, or set the \`nativeButton\` prop on the component to \`false\`.${ownerStackMessage}`, |
There was a problem hiding this comment.
Would this make more sense? I'm struggling to understand what "which does not match the default" mean.
| `A component that acts as a button was not rendered as a native <button>, which does not match the default. Ensure that the element passed to the \`render\` prop of the component is a real <button>, or set the \`nativeButton\` prop on the component to \`false\`.${ownerStackMessage}`, | |
| `A component that acts as a button was not rendered as a native <button>. For the component to behave correctly, it needs the `nativeButton` boolean prop to match the actual DOM node rendered. To fix this, ensure that the element passed to the \`render\` prop of the component is a real <button>, or set the \`nativeButton\` prop on the component to \`false\`.${ownerStackMessage}`, |
matching:
- Say what’s the problem
- Say why it's a problem
- Point out how to solve the problem
There was a problem hiding this comment.
"Default" means the "default rendered element tag", so e.g. a component's JSDoc says "Renders a <button> element."
Yeah, the error message is missing the second dot point (it's needed for SSR), but handles the first and third.
|
Nice 👍 |
Fixes #3779, at least for React 19.1+ (when
React.captureOwnerStack()was released). React 18 is supposedly better at printing the component stack trace inside effects already, though.Before (+ expanded):

After (collapsed):
