Skip to content

Freeze IntersectionObserver threshold configuration (#60310) - #60310

Merged
meta-codesync[bot] merged 2 commits into
react:mainfrom
rubennorte:export-D134237377
Nov 26, 2026
Merged

meta-codesync[bot] merged 2 commits into
react:mainfrom
rubennorte:export-D134237377

Conversation

@rubennorte

@rubennorte rubennorte commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary:

Context

IntersectionObserver exposes normalized threshold arrays as read-only configuration, but a static read-only type does not prevent JavaScript callers from mutating the arrays at runtime.

Changes

Freeze normalized thresholds and rnRootThresholds arrays at construction without freezing caller-owned inputs. Add public cases for mutation rejection, input independence, and default/scalar/empty configurations. Native threshold lookup and supported threshold counts remain unchanged.

Changelog:
[General][Fixed] - Keep IntersectionObserver threshold arrays immutable

Reviewed By: javache

Differential Revision: D134237377

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 26, 2026
@meta-codesync

meta-codesync Bot commented Nov 26, 2026

Copy link
Copy Markdown

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

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at 1433a132bc89.

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot changed the title Freeze IntersectionObserver threshold configuration Freeze IntersectionObserver threshold configuration (#60310) Nov 26, 2026
rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
Summary:

## Context

IntersectionObserver exposes normalized threshold arrays as read-only configuration, but a static read-only type does not prevent JavaScript callers from mutating the arrays at runtime.

## Changes

Freeze normalized `thresholds` and `rnRootThresholds` arrays at construction without freezing caller-owned inputs. Add public cases for mutation rejection, input independence, and default/scalar/empty configurations. Native threshold lookup and supported threshold counts remain unchanged.

Changelog:
[General][Fixed] - Keep IntersectionObserver threshold arrays immutable

Reviewed By: javache

Differential Revision: D134237377
Summary:

## Context

Benchmarks should cover how IntersectionObserver is normally configured: one or two thresholds, with ten and one hundred as bounds.

## Changes

Keep all public benchmark additions in this first, benchmark-only diff. Cover 1, 2, 10, and 100 thresholds, deep implicit/explicit roots, and target/root ratio reads. Parameterize callback-count assertions for the threshold count. No runtime implementation or API threshold-count limit is changed.

## Baseline benchmark results

Optimized Fantom (native + Hermes bytecode), headless Linux, fixed CPU affinity. This benchmark-only baseline includes landed scrollMargin support, but no runtime changes from this stack. Values are median CPU time per complete invocation from the current run; setup/assertions are outside timed work. Scaling cases have 100 measured invocations and cover 1/2 thresholds plus 10/100 bounds.

| Benchmark | Baseline CPU |
| --- | --- |
| `Read intersectionRatio 1000 times` | 5.105 ms |
| `Read rnRootIntersectionRatio 1000 times` | 4.962 ms |
| `Scroll 100 targets, depth 1, 1 thresholds, implicit root` | 7.238 ms |
| `Scroll 100 targets, depth 1, 2 thresholds, implicit root` | 7.513 ms |
| `Scroll 100 targets, depth 1, 10 thresholds, implicit root` | 8.560 ms |
| `Scroll 100 targets, depth 1, 100 thresholds, implicit root` | 20.442 ms |
| `Scroll 100 targets, depth 40, 1 thresholds, implicit root` | 38.032 ms |
| `Scroll 100 targets, depth 40, 1 thresholds, explicit root` | 46.293 ms |

Scrolling includes mounting and intersection computation, plus callbacks when thresholds are crossed. Ratio rows measure consumer reads, not notification dispatch.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D134252378
Summary:

## Context

IntersectionObserver exposes normalized threshold arrays as read-only configuration, but a static read-only type does not prevent JavaScript callers from mutating the arrays at runtime.

## Changes

Freeze normalized `thresholds` and `rnRootThresholds` arrays at construction without freezing caller-owned inputs. Add public cases for mutation rejection, input independence, and default/scalar/empty configurations. Native threshold lookup and supported threshold counts remain unchanged.

Changelog:
[General][Fixed] - Keep IntersectionObserver threshold arrays immutable

Reviewed By: javache

Differential Revision: D134237377
rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
Summary:

## Context

IntersectionObserver exposes normalized threshold arrays as read-only configuration, but a static read-only type does not prevent JavaScript callers from mutating the arrays at runtime.

## Changes

Freeze normalized `thresholds` and `rnRootThresholds` arrays at construction without freezing caller-owned inputs. Add public cases for mutation rejection, input independence, and default/scalar/empty configurations. Native threshold lookup and supported threshold counts remain unchanged.

Changelog:
[General][Fixed] - Keep IntersectionObserver threshold arrays immutable

Reviewed By: javache

Differential Revision: D134237377
rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
Summary:

## Context

IntersectionObserver exposes normalized threshold arrays as read-only configuration, but a static read-only type does not prevent JavaScript callers from mutating the arrays at runtime.

## Changes

Freeze normalized `thresholds` and `rnRootThresholds` arrays at construction without freezing caller-owned inputs. Add public cases for mutation rejection, input independence, and default/scalar/empty configurations. Native threshold lookup and supported threshold counts remain unchanged.

Changelog:
[General][Fixed] - Keep IntersectionObserver threshold arrays immutable

Reviewed By: javache

Differential Revision: D134237377
@meta-codesync
meta-codesync Bot merged commit 35a784b into react:main Nov 26, 2026
96 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @rubennorte in 35a784b

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants