Skip to content

Conversation

@rickhanlonii
Copy link
Member

@rickhanlonii rickhanlonii commented Jan 12, 2026

Requires full error message in assert helpers.

Some of the error messages we asset on add a native javascript stack trace, which would be a pain to add to the messages and maintain. This PR allows you to just add \n in <stack> placeholder to the error message to denote a native stack trace is present in the message.


Note: i vibe coded this so it was a pain to backtrack this to break this into a stack, I tried and gave up, sorry.

Update test assertions to include the complete component stack trace
rather than partial stacks. This ensures tests validate the full
owner stack as it would appear in development.
@meta-cla meta-cla bot added the CLA Signed label Jan 12, 2026
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Jan 12, 2026
@react-sizebot
Copy link

react-sizebot commented Jan 12, 2026

Comparing: 5aec1b2...e61f352

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.84 kB 6.84 kB +0.05% 1.88 kB 1.88 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 607.60 kB 607.60 kB = 107.53 kB 107.53 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.84 kB 6.84 kB +0.05% 1.88 kB 1.88 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 666.83 kB 666.83 kB = 117.42 kB 117.42 kB
facebook-www/ReactDOM-prod.classic.js = 692.91 kB 692.91 kB = 121.92 kB 121.92 kB
facebook-www/ReactDOM-prod.modern.js = 683.34 kB 683.34 kB = 120.31 kB 120.31 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against e61f352

Add two new placeholders for console error assertions:

1. [Server] - expands to the ANSI escape sequence for server badge
   Instead of: '\u001b[0m\u001b[7m Server \u001b[0mError: message'
   Write: '[Server] Error: message'

2. \n    in <stack> - matches JavaScript Error stack traces
   Instead of matching the full error stack manually
   Write: 'Error: message\n    in <stack>'

The error stack placeholder validates that it's only used for actual
Error stack traces (messages starting with "Error:" that have file:line:col
frames), not for React component stacks.

Also adds validation to catch misuse of these placeholders and provides
helpful error messages guiding developers to the correct usage.
Copy link
Collaborator

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

Comment on lines 234 to 239
// Error stack traces start with "Error:" and contain "at" frames with file paths
// Component stacks contain "in ComponentName" patterns
// This helps validate that \n in <stack> is used correctly
const isLikelyAnErrorStackTrace = message =>
typeof message === 'string' &&
message.includes('Error:') &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your implementation already accounts for e.g. TypeError() having TypeError: bla when stringified but the comments still says "start". Should prob update the comment to call out that includes is used to handle other kind of errors.

Also the input here is the stringified error instance not just the message. .message doesn't include the error name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I noticed this while vibe coding too and meant to get back to it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment - The message does include the error name (and stack trace). I was surprised about this too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the tests to log an error, showing the behavior (and confirmed with logging).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment - The message does include the error name (and stack trace). I was surprised about this too.

That sounds wrong. Maybe you're reading .stack instead of .message? .stack would include name, message, and stacktrace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was wrong, then this wouldn't work right? Like this function would noop, but if you noop it then the tests fail. Maybe there's a shim or console override adding it?

@rickhanlonii rickhanlonii merged commit 3e1abcc into facebook:main Jan 13, 2026
234 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants