fix[describeClassComponentFrame]: invoke constructor with new keyword (#36455)
For JavaScript runtimes that do not have [`Reflect`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect) supported, we had a fall back that was calling the constructor with overridden `this` context via ``` fn.apply(Fake.prototype); ``` In ES6, it is required to call constructor only with the `new` keyword, otherwise the runtime is expected to throw a corresponding TypeError: ``` TypeError: Class constructor <> cannot be invoked without 'new' ``` We've observed this error in Hermes runtime, but this is applicable to V8 or any other runtime. The only reason why V8 wasn't affected is because it implemented Reflect APIs. Instead of the incorrect call, we will fall back to calling `new fn()`, but with a temporary patched prototype of the class, which would make a trap out of the setter for `props` object. We use the same approach when `Reflect` APIs are available, but instead of modifying the prototype, we pass the fake context: https://github.com/facebook/react/blob/d5736f098edee62c44f27b053e6e48f5fa443803/packages/shared/ReactComponentStackFrame.js#L129-L148 --- See tests implemented. Without the changes, the test would fail with the `TypeError` mentioned above.
R
Ruslan Lesiutin committed
8fc5763b8acb3fe8ca8c350cff7675a5bce2b332
Parent: d5736f0
Committed by GitHub <noreply@github.com>
on 5/13/2026, 9:05:14 PM