Skip to content

Type react-devtools-hook-installer and react-devtools-hook-settings-injector messages#391

Closed
everettbu wants to merge 1 commit into
mainfrom
sebbie/01-21-type_react-devtools-hook-installer_and_react-devtools-hook-settings-injector_messages
Closed

Type react-devtools-hook-installer and react-devtools-hook-settings-injector messages#391
everettbu wants to merge 1 commit into
mainfrom
sebbie/01-21-type_react-devtools-hook-installer_and_react-devtools-hook-settings-injector_messages

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of facebook/react#35586
Original author: eps1lon


Partially types the message protocol in the content scripts.

The downside is a false sense of safety because we have to restrict the received events to known events. Extending the received events to all possible events would not allow type narrowing.

@everettbu everettbu added CLA Signed React Core Team Opened by a member of the React Core Team labels Jan 21, 2026
@everettbu
everettbu marked this pull request as ready for review January 21, 2026 16:22
@greptile-apps

greptile-apps Bot commented Jan 21, 2026

Copy link
Copy Markdown

Greptile Summary

Added Flow type definitions for the message protocol between content scripts (react-devtools-hook-installer and react-devtools-hook-settings-injector). Introduced a new messages.js module that defines typed message events and payloads, and updated MessageEvent in Flow environment definitions to support generic type parameters.

Key improvements:

  • Created centralized type definitions for message protocol in messages.js
  • Refactored settings initialization in hookSettingsInjector.js to construct a complete DevToolsHookSettings object with proper defaults
  • Updated Flow environment files to make MessageEvent generic
  • Added type annotations to message listeners for better type safety

The PR acknowledges a tradeoff: type narrowing is limited because the union types aren't perfectly discriminated, but the added types still provide valuable safety over untyped messages.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes add type safety to existing message passing code without altering logic. The refactoring in hookSettingsInjector.js improves code clarity by explicitly constructing the settings object rather than mutating it. All changes are incremental improvements to type safety with no breaking changes to behavior.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react-devtools-extensions/src/contentScripts/messages.js New file defining typed message protocol for content scripts with proper Flow types for message events and payloads
packages/react-devtools-extensions/src/contentScripts/installHook.js Added Flow types and switched to typed message events with improved type narrowing on payload
packages/react-devtools-extensions/src/contentScripts/hookSettingsInjector.js Added Flow types, refactored settings construction to ensure complete DevToolsHookSettings object with defaults
flow-typed/environments/dom.js Made MessageEvent generic with Data type parameter to support typed message data

@everettbu

Copy link
Copy Markdown
Author

Upstream PR was closed or merged. Code is synced via branch mirror.

@everettbu everettbu closed this Jan 21, 2026
@everettbu
everettbu deleted the sebbie/01-21-type_react-devtools-hook-installer_and_react-devtools-hook-settings-injector_messages branch January 21, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants