Skip to content

Let several tools observe JavaScript evaluation (#60562) - #60562

Open
RobertHerhold wants to merge 2 commits into
react:mainfrom
RobertHerhold:export-D136024546
Open

RobertHerhold wants to merge 2 commits into
react:mainfrom
RobertHerhold:export-D136024546

Conversation

@RobertHerhold

@RobertHerhold RobertHerhold commented Dec 4, 2026 •

Copy link
Copy Markdown

Summary:

setJSEvaluationObserver kept one process-wide observer, so a second tool installing its own silently disconnected the first. Replace it with addJSEvaluationObserver and removeJSEvaluationObserver:

  • Every added observer is called before each evaluation, in the order added. Adding one twice has no effect.
  • addJSEvaluationObserver returns how many evaluations ReactInstance had already made in the process, so an observer added after JavaScript ran can tell it missed some.
  • An exception an observer throws is caught and ignored, so an observer cannot stop JavaScript from loading or keep later observers from running.

Changelog:
[General][Changed] - Replace setJSEvaluationObserver with addJSEvaluationObserver and removeJSEvaluationObserver

Differential Revision: D136024546

@meta-codesync

meta-codesync Bot commented Dec 4, 2026

Copy link
Copy Markdown

@RobertHerhold has exported this pull request. If you are a Meta employee, you can view the originating Diff in D136024546.

@meta-codesync meta-codesync Bot changed the title Let several tools observe JavaScript evaluation Let several tools observe JavaScript evaluation (#60562) Dec 4, 2026
RobertHerhold added a commit to RobertHerhold/react-native that referenced this pull request Dec 4, 2026
Summary:

`setJSEvaluationObserver` kept one process-wide observer, so a second tool installing its own silently disconnected the first. Replace it with `addJSEvaluationObserver` and `removeJSEvaluationObserver`:

- Every added observer is called before each evaluation, in the order added. Adding one twice has no effect.
- `addJSEvaluationObserver` returns how many evaluations `ReactInstance` had already made in the process, so an observer added after JavaScript ran can tell it missed some.
- An exception an observer throws is caught and ignored, so an observer cannot stop JavaScript from loading or keep later observers from running.

Changelog:
[General][Changed] - Replace `setJSEvaluationObserver` with `addJSEvaluationObserver` and `removeJSEvaluationObserver`

Differential Revision: D136024546
RobertHerhold added a commit to RobertHerhold/react-native that referenced this pull request Dec 4, 2026
Summary:

`setJSEvaluationObserver` kept one process-wide observer, so a second tool installing its own silently disconnected the first. Replace it with `addJSEvaluationObserver` and `removeJSEvaluationObserver`:

- Every added observer is called before each evaluation, in the order added. Adding one twice has no effect.
- `addJSEvaluationObserver` returns how many evaluations `ReactInstance` had already made in the process, so an observer added after JavaScript ran can tell it missed some.
- An exception an observer throws is caught and ignored, so an observer cannot stop JavaScript from loading or keep later observers from running.

Changelog:
[General][Changed] - Replace `setJSEvaluationObserver` with `addJSEvaluationObserver` and `removeJSEvaluationObserver`

Differential Revision: D136024546




Signed-off-by: Rob Herhold <rherhold@meta.com>
RobertHerhold added a commit to RobertHerhold/react-native that referenced this pull request Dec 4, 2026
Summary:

`setJSEvaluationObserver` kept one process-wide observer, so a second tool installing its own silently disconnected the first. Replace it with `addJSEvaluationObserver` and `removeJSEvaluationObserver`:

- Every added observer is called before each evaluation, in the order added. Adding one twice has no effect.
- `addJSEvaluationObserver` returns how many evaluations `ReactInstance` had already made in the process, so an observer added after JavaScript ran can tell it missed some.
- An exception an observer throws is caught and ignored, so an observer cannot stop JavaScript from loading or keep later observers from running.

Changelog:
[General][Changed] - Replace `setJSEvaluationObserver` with `addJSEvaluationObserver` and `removeJSEvaluationObserver`

Differential Revision: D136024546
…evaluates (react#60561)

Summary:

Development tooling sometimes needs to know exactly which JavaScript a process ran, for example to tie a recording to the source it came from. `ReactInstance` evaluates JavaScript in four places: the main bundle (`loadScript`), segments registered from files (`registerSegment`), source evaluated through `globalEvalWithSourceUrl` (lazy segments fetched from a dev server and Fast Refresh updates), and Static Hermes units compiled into the binary.

This adds `setJSEvaluationObserver`, a process-wide hook in `react/runtime/JSEvaluationObserver.h`. `ReactInstance` calls the installed observer on the JS thread immediately before each evaluation, with the exact bytes it is about to evaluate, the source URL and the kind of evaluation. With no observer installed, each path only counts the evaluation; `setJSEvaluationObserver` returns that count, so an observer installed late can tell that it missed some.

The header is in the for-frameworks tier, like `ReactMarker`.

Changelog:
[General][Added] - Add `setJSEvaluationObserver` to observe the JavaScript `ReactInstance` evaluates

Differential Revision: D136024543
Summary:

`setJSEvaluationObserver` kept one process-wide observer, so a second tool installing its own silently disconnected the first. Replace it with `addJSEvaluationObserver` and `removeJSEvaluationObserver`:

- Every added observer is called before each evaluation, in the order added. Adding one twice has no effect.
- `addJSEvaluationObserver` returns how many evaluations `ReactInstance` had already made in the process, so an observer added after JavaScript ran can tell it missed some.
- An exception an observer throws is caught and ignored, so an observer cannot stop JavaScript from loading or keep later observers from running.

Changelog:
[General][Changed] - Replace `setJSEvaluationObserver` with `addJSEvaluationObserver` and `removeJSEvaluationObserver`

Differential Revision: D136024546

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant