Skip to content

fix(core): guard CONSUMED_PARAMS against non-extensible params#13042

Merged
satya164 merged 4 commits intoreact-navigation:mainfrom
gtokman:fix/consumed-params-frozen-object
Mar 19, 2026
Merged

fix(core): guard CONSUMED_PARAMS against non-extensible params#13042
satya164 merged 4 commits intoreact-navigation:mainfrom
gtokman:fix/consumed-params-frozen-object

Conversation

@gtokman
Copy link
Copy Markdown
Contributor

@gtokman gtokman commented Mar 19, 2026

Summary

  • Adds an Object.isExtensible() check before the Object.defineProperty(route.params, CONSUMED_PARAMS, ...) call in useNavigationBuilder
  • When using React Compiler (which freezes objects) or other tools that make route.params non-extensible, the current code throws TypeError: Cannot add new property 'CONSUMED_PARAMS'
  • This is a minimal, safe fix — if params are frozen, the property simply won't be set, and the next navigation will re-consume params as expected

Related

Code 2026-03-19 11 14 57

When using React Compiler or other tools that freeze objects,
`route.params` can become non-extensible. The `Object.defineProperty`
call to set `CONSUMED_PARAMS` then throws:
`TypeError: Cannot add new property 'CONSUMED_PARAMS'`

Add an `Object.isExtensible()` check before attempting to define the
property, matching the pattern suggested in react-navigation#13033.

Fixes react-navigation#13033
@github-actions
Copy link
Copy Markdown

Hey @gtokman! Thanks for opening your first pull request in this repo. If you haven't already, make sure to read our contribution guidelines.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 19, 2026

Deploy Preview for react-navigation-example ready!

Name Link
🔨 Latest commit 35beb9c
🔍 Latest deploy log https://app.netlify.com/projects/react-navigation-example/deploys/69bc1404ac400e0008dc7d42
😎 Deploy Preview https://deploy-preview-13042--react-navigation-example.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@gtokman gtokman closed this Mar 19, 2026
@github-actions
Copy link
Copy Markdown

Hey @autofix-ci[bot]! Thanks for opening your first pull request in this repo. If you haven't already, make sure to read our contribution guidelines.

@gtokman gtokman reopened this Mar 19, 2026
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 19, 2026

Deploy Preview for react-navigation-example ready!

Name Link
🔨 Latest commit b67f128
🔍 Latest deploy log https://app.netlify.com/projects/react-navigation-example/deploys/69bc26cb2a22c70008120dda
😎 Deploy Preview https://deploy-preview-13042--react-navigation-example.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

…ARAMS

Replace the symbol-based mutation approach with a module-level WeakSet
to track consumed params. This avoids mutating route.params entirely,
which fixes compatibility with React Compiler and other tools that
freeze objects.

The WeakSet approach:
- Does not mutate route.params (works with frozen/sealed objects)
- Automatically cleans up when params objects are GC'd (no memory leaks)
- Preserves the same semantics: params are marked as consumed after
  being processed by a nested navigator
@gtokman gtokman force-pushed the fix/consumed-params-frozen-object branch 2 times, most recently from b786210 to 37df7d3 Compare March 19, 2026 16:05
…tracking

Instead of a global WeakSet, store consumed params state per navigator
instance using a React context provided by SceneView.

- Add ConsumedParamsContext with WeakRef<object> | null state
- SceneView provides the context, scoping tracking to each navigator
- useNavigationBuilder consumes the context to check/set consumed params
- No mutation of route.params (works with frozen objects / React Compiler)
- No shared state between navigator instances

Fixes react-navigation#13033
@gtokman gtokman force-pushed the fix/consumed-params-frozen-object branch from 37df7d3 to 9fcfa2e Compare March 19, 2026 16:12
Copy link
Copy Markdown
Member

@satya164 satya164 left a comment

Choose a reason for hiding this comment

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

Thank you

@satya164 satya164 merged commit 3de9e89 into react-navigation:main Mar 19, 2026
8 of 10 checks passed
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.

2 participants