fix(@astrojs/react): suppress spurious "Invalid hook call" warning in React 19 dev mode#17239
fix(@astrojs/react): suppress spurious "Invalid hook call" warning in React 19 dev mode#17239FrancoKaddour wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 7b8698f The changes in this PR will be included in the next version bump. This PR includes changesets to release 38 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
fkatsuhiro
left a comment
There was a problem hiding this comment.
@FrancoKaddour san
Thank you for your implementation!
Could you create test for reproduce this issue? We want to provide occure same issue in the future.
|
Thanks for the review! Added a regression test in |
Direct import of server.ts fails at runtime because server.ts resolves sibling imports as .js (ESM convention), which only exist after the package is built. A fixture-based integration test is needed instead.
|
Apologies for the noise — had to revert the test in the follow-up commit. The test imported server.ts directly, but server.ts resolves sibling imports as .js (ESM convention pointing to compiled output), which doesn't exist when running source files in the test environment. The Node.js runner fails with ERR_MODULE_NOT_FOUND before any test runs. A proper regression test for this needs to be a fixture-based integration test — an Astro project with a hook-using React component, capturing console.error output during check(). Happy to add that as a follow-up if you'd like. |
Fixes #16767
In React 19 dev mode, the
check()renderer probe calls the component inside aTesterwrapper during SSR. When the component uses hooks, React emits an "Invalid hook call" warning because the hooks run inTester's render context instead of the component's own.The warning is a false positive — the component works correctly. This wraps the probe render with a targeted
console.errorsuppressor that filters only the "Invalid hook call" message, leaving all other errors intact.