fix: don't mutate component props (crashes under React's frozen props in dev)#795
Open
nn1900 wants to merge 1 commit into
Open
fix: don't mutate component props (crashes under React's frozen props in dev)#795nn1900 wants to merge 1 commit into
nn1900 wants to merge 1 commit into
Conversation
The `Camera` component mutates its own `props` to convert optional int/float
view props to sentinels for codegen:
props.zoom = props.zoom ?? -1;
props.maxZoom = props.maxZoom ?? -1;
// ...
React freezes `element.props` in development, so this throws as soon as the
module runs in JavaScript strict mode:
Render Error: Cannot add new property 'zoom'
ES modules are always strict, and bundlers increasingly emit per-module
`"use strict"` (e.g. Metro 0.84 injects it for `sourceType: "module"`), so this
crashes Camera in any dev build that freezes props (React 18 and 19 both do).
It was masked before only where the module happened to run sloppy (older Metro /
`@react-native/babel-preset` `strictMode: false`), where the frozen write is a
silent no-op, and in release builds (React doesn't freeze there).
Fix: build a new object with the defaults and spread it into NativeCamera,
instead of mutating the (frozen) `props`. No behavior change otherwise.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Cameramutates its ownpropsto turn optional int/float view props into sentinels for codegen:In a development build this throws the moment
<Camera>renders:(Component stack points at
Camera.ios.tsx/Camera.android.tsx.)Why
element.propsin dev (Object.freezein the JSX dev runtime — React 18 and 19; release builds do not freeze)."use strict"— e.g. Metro 0.84 injects it for everysourceType: "module"file (metro-transform-worker). React Native 0.85 ships that Metro.So on a modern toolchain (RN 0.85 / Expo SDK 56, dev build) the mutation throws. It was masked before only where the module happened to run sloppy (older Metro, or
@react-native/babel-preset’sstrictMode: false) — there the frozen write is a silent no-op — and in release builds, where props aren’t frozen. That’s why it hasn’t been widely reported despite shipping since v16.This is unrelated to
React.StrictModeand to the React Compiler; it’s plain JS"use strict"+ React’s dev prop-freeze.Fix
Build a new object with the defaults and spread it into
NativeCamera, instead of mutating the (frozen)props. Behavior is otherwise unchanged. Applied to bothCamera.ios.tsxandCamera.android.tsx(Android keeps itsprocessColorhandling).Repro (minimal)