Skip to content

[0.81] Prevent partially initialized TurboModules during shutdown - #16369

Open
Khalef Hosany (Khalef1) wants to merge 1 commit into
0.81-stablefrom
user/khosany/fix-turbomodule-teardown-11996737
Open

[0.81] Prevent partially initialized TurboModules during shutdown#16369
Khalef Hosany (Khalef1) wants to merge 1 commit into
0.81-stablefrom
user/khosany/fix-turbomodule-teardown-11996737

Conversation

@Khalef1

@Khalef1 Khalef Hosany (Khalef1) commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

Watson reports an access violation in BlobTurboModule::CreateFromParts because m_resource is null. This regressed after #16237: during instance teardown, REACT_INIT is skipped when the runtime handle is null, but the lazy TurboModule can still be returned to JavaScript. The module is then callable without its initializer having populated its state. The same partial-initialization pattern can affect other lazy TurboModules.

What

  • Refuse lazy TurboModule creation after the React context or JSI runtime is unavailable.
  • Hold the acquired runtime handle throughout module registration so teardown cannot invalidate it between the availability check and initializer execution.
  • Release the temporary runtime handle after registration to avoid extending the runtime lifetime.
  • Add the react-native-windows patch change file.

Screenshots

Not applicable.

Testing

  • yarn format:verify
  • yarn beachball check --branch origin/0.81-stable

Changelog

Should this change be included in the release notes: yes

Prevent lazy TurboModules from being created without a runtime during shutdown.

Microsoft Reviewers: Open in CodeFlow

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e5dad4bf-4f71-43ee-aa7f-d2f11d43121e
Copilot AI balanced review requested due to automatic review settings August 15, 2026 07:06
@Khalef1
Khalef Hosany (Khalef1) requested a review from a team as a code owner August 15, 2026 07:06

Copilot AI 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.

Pull request overview

Prevents lazy TurboModules from being returned with uninitialized runtime-dependent state during shutdown.

Changes:

  • Validates and retains the JSI runtime during module registration.
  • Releases the temporary runtime handle afterward.
  • Adds a patch change file.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
vnext/Microsoft.ReactNative/TurboModulesProvider.cpp Guards and stabilizes TurboModule initialization.
change/react-native-windows-c5366f79-8343-45d0-9916-3f13b872c4d8.json Records the patch release note.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +39 to +40
TurboModuleBuilder(const IReactContext &reactContext, IInspectable runtimeHandle) noexcept
: m_reactContext(reactContext), m_runtimeHandle(std::move(runtimeHandle)) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants