Skip to content

Detect cyclic values in dynamicFromValue in debug builds - #60297

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
dalves:export-D132584875
Nov 25, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
dalves:export-D132584875

Conversation

@dalves

@dalves dalves commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary:
A cyclic JavaScript value can leave prop conversion stuck while memory grows. Native debug builds now detect the cycle and throw a JSError, returning control to JavaScript instead of hanging. Release-build conversion is unchanged.

How the hang happens

  1. Fabric converts a component's raw props through RawProps::toDynamic and jsi::dynamicFromValue.
  2. The converter walks objects with an explicit stack. A cycle keeps expanding the same path instead of finishing.
  3. The call never returns, so the JavaScript thread remains stuck while the partial output and pending handles grow.

What changes
When NDEBUG is not defined, the converter uses Brent's algorithm to detect cycles without a visited set. Cyclic values throw, while acyclic values—including objects shared across paths—continue to convert normally.

When NDEBUG is defined, all cycle-detection code is excluded: depth fields and arguments, ancestor storage, comparisons and updates. The release converter retains its original code and behavior, including the existing hang on cyclic values. This is a native-build guard, not the JavaScript __DEV__ flag.

Changelog:
[General][Fixed] - Detect cyclic JavaScript values during debug-build conversion to folly::dynamic

Reviewed By: javache

Differential Revision: D132584875

Summary:
A cyclic JavaScript value can leave prop conversion stuck while memory grows. Native debug builds now detect the cycle and throw a `JSError`, returning control to JavaScript instead of hanging. Release-build conversion is unchanged.

**How the hang happens**
1. Fabric converts a component's raw props through `RawProps::toDynamic` and `jsi::dynamicFromValue`.
2. The converter walks objects with an explicit stack. A cycle keeps expanding the same path instead of finishing.
3. The call never returns, so the JavaScript thread remains stuck while the partial output and pending handles grow.

**What changes**
When `NDEBUG` is not defined, the converter uses Brent's algorithm to detect cycles without a visited set. Cyclic values throw, while acyclic values—including objects shared across paths—continue to convert normally.

When `NDEBUG` is defined, all cycle-detection code is excluded: depth fields and arguments, ancestor storage, comparisons and updates. The release converter retains its original code and behavior, including the existing hang on cyclic values. This is a native-build guard, not the JavaScript `__DEV__` flag.

Changelog:
[General][Fixed] - Detect cyclic JavaScript values during debug-build conversion to folly::dynamic

Reviewed By: javache

Differential Revision: D132584875
@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 25, 2026
@meta-codesync

meta-codesync Bot commented Nov 25, 2026

Copy link
Copy Markdown

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

@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 Bot pushed a commit to meta/hermes that referenced this pull request Nov 25, 2026
Summary:
X-link: react/react-native#60297

A cyclic JavaScript value can leave prop conversion stuck while memory grows. Native debug builds now detect the cycle and throw a `JSError`, returning control to JavaScript instead of hanging. Release-build conversion is unchanged.

**How the hang happens**
1. Fabric converts a component's raw props through `RawProps::toDynamic` and `jsi::dynamicFromValue`.
2. The converter walks objects with an explicit stack. A cycle keeps expanding the same path instead of finishing.
3. The call never returns, so the JavaScript thread remains stuck while the partial output and pending handles grow.

**What changes**
When `NDEBUG` is not defined, the converter uses Brent's algorithm to detect cycles without a visited set. Cyclic values throw, while acyclic values—including objects shared across paths—continue to convert normally.

When `NDEBUG` is defined, all cycle-detection code is excluded: depth fields and arguments, ancestor storage, comparisons and updates. The release converter retains its original code and behavior, including the existing hang on cyclic values. This is a native-build guard, not the JavaScript `__DEV__` flag.

Changelog:
[General][Fixed] - Detect cyclic JavaScript values during debug-build conversion to folly::dynamic

Reviewed By: javache

Differential Revision: D132584875

fbshipit-source-id: 1078621fe5aae7f8f3ac48f2f07c2488934d6479
meta-codesync Bot pushed a commit to meta/hermes that referenced this pull request Nov 25, 2026
Summary:
X-link: react/react-native#60297

A cyclic JavaScript value can leave prop conversion stuck while memory grows. Native debug builds now detect the cycle and throw a `JSError`, returning control to JavaScript instead of hanging. Release-build conversion is unchanged.

**How the hang happens**
1. Fabric converts a component's raw props through `RawProps::toDynamic` and `jsi::dynamicFromValue`.
2. The converter walks objects with an explicit stack. A cycle keeps expanding the same path instead of finishing.
3. The call never returns, so the JavaScript thread remains stuck while the partial output and pending handles grow.

**What changes**
When `NDEBUG` is not defined, the converter uses Brent's algorithm to detect cycles without a visited set. Cyclic values throw, while acyclic values—including objects shared across paths—continue to convert normally.

When `NDEBUG` is defined, all cycle-detection code is excluded: depth fields and arguments, ancestor storage, comparisons and updates. The release converter retains its original code and behavior, including the existing hang on cyclic values. This is a native-build guard, not the JavaScript `__DEV__` flag.

Changelog:
[General][Fixed] - Detect cyclic JavaScript values during debug-build conversion to folly::dynamic

Reviewed By: javache

Differential Revision: D132584875

fbshipit-source-id: 1078621fe5aae7f8f3ac48f2f07c2488934d6479
meta-codesync Bot pushed a commit to meta/hermes that referenced this pull request Nov 25, 2026
Summary:
X-link: react/react-native#60297

A cyclic JavaScript value can leave prop conversion stuck while memory grows. Native debug builds now detect the cycle and throw a `JSError`, returning control to JavaScript instead of hanging. Release-build conversion is unchanged.

**How the hang happens**
1. Fabric converts a component's raw props through `RawProps::toDynamic` and `jsi::dynamicFromValue`.
2. The converter walks objects with an explicit stack. A cycle keeps expanding the same path instead of finishing.
3. The call never returns, so the JavaScript thread remains stuck while the partial output and pending handles grow.

**What changes**
When `NDEBUG` is not defined, the converter uses Brent's algorithm to detect cycles without a visited set. Cyclic values throw, while acyclic values—including objects shared across paths—continue to convert normally.

When `NDEBUG` is defined, all cycle-detection code is excluded: depth fields and arguments, ancestor storage, comparisons and updates. The release converter retains its original code and behavior, including the existing hang on cyclic values. This is a native-build guard, not the JavaScript `__DEV__` flag.

Changelog:
[General][Fixed] - Detect cyclic JavaScript values during debug-build conversion to folly::dynamic

Reviewed By: javache

Differential Revision: D132584875

fbshipit-source-id: 1078621fe5aae7f8f3ac48f2f07c2488934d6479
@meta-codesync
meta-codesync Bot merged commit 0c688a7 into react:main Nov 25, 2026
103 of 104 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @dalves in 0c688a7

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 25, 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