Skip to content

Fix hash generation for declare const types in API snapshot #54818#54822

Closed
emily8rown wants to merge 1 commit intofacebook:mainfrom
emily8rown:export-D88653322
Closed

Fix hash generation for declare const types in API snapshot #54818#54822
emily8rown wants to merge 1 commit intofacebook:mainfrom
emily8rown:export-D88653322

Conversation

@emily8rown
Copy link
Copy Markdown
Contributor

Summary:
Fixes hash generation in versionExportedApis.js to properly track changes to declare const type declarations like AccessibilityInfo_default.

Previously, changes to APIs (e.g., AccessibilityInfo) would not always update their hashes in ReactNativeApi.d.ts, causing the breaking change detection to miss actual API changes.

Problem

Three issues prevented proper hash tracking:

  1. VariableDeclaration types weren't tracked - declare const X: {...} was not in the list of tracked declaration types
  2. Duplicate declarations caused overwrites - declare type X = typeof X would overwrite declare const X: typeof X_default in the declarations map, losing the dependency on X_default
  3. typeof X queries weren't extracting dependencies - references via typeof weren't being added to the dependency graph

Fix

  • Add t.isVariableDeclaration(node) to tracked types with proper name extraction
  • Prevent overwriting existing declarations (first declaration wins)
  • Handle TSTypeQuery nodes to extract typeof X dependencies

Note on Hash Changes

This PR causes many hashes to change, even for types that haven't been modified. This is expected because the hash computation now includes declare const dependencies that were previously ignored.

Before: AccessibilityInfo hash only included declare type AccessibilityInfo = typeof AccessibilityInfo (self-reference)
After: Hash now includes declare const AccessibilityInfo: typeof AccessibilityInfo_default + the full AccessibilityInfo_default type

This is a one-time recalibration. Going forward, changes to these types will be properly detected.

Changelog:

[GENERAL] [FIXED] - Fix hash generation for declare const types in API snapshot

Differential Revision: D88653322

@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 Dec 9, 2025
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Dec 9, 2025

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

@react-native-bot
Copy link
Copy Markdown
Collaborator

react-native-bot commented Dec 9, 2025


Warnings
⚠️ ❗ JavaScript API change detected - This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API. Please include a clear changelog message. This change will be subject to extra review.

This change was flagged as: BREAKING

Generated by 🚫 dangerJS against 7a68383

…54818

Summary:
Updates hash generation in `versionExportedApis.js` to track changes to `declare const` type declarations like `AccessibilityInfo_default`.

Previously, changes to APIs (e.g., `AccessibilityInfo`) would not always update their hashes in `ReactNativeApi.d.ts`, causing the breaking change detection to miss actual API changes.

Three issues prevented proper hash tracking:

1. **`VariableDeclaration` types weren't tracked** - `declare const X: {...}` was not in the list of tracked declaration types
2. **Duplicate declarations caused overwrites** - `declare type X = typeof X` would overwrite `declare const X: typeof X_default` in the declarations map, losing the dependency on `X_default`
3. **`typeof X` queries weren't extracting dependencies** - references via `typeof` weren't being added to the dependency graph

## Fix

- Add `t.isVariableDeclaration(node)` to tracked types with proper name extraction
- Prevent overwriting existing declarations (first declaration wins)
- Handle `TSTypeQuery` nodes to extract `typeof X` dependencies

### Note on Hash Changes

This PR causes many hashes to change, even for types that haven't been modified. This is expected because the hash computation now includes `declare const` dependencies that were previously ignored.

**Before:** `AccessibilityInfo` hash only included `declare type AccessibilityInfo = typeof AccessibilityInfo` (self-reference)
**After:** Hash now includes `declare const AccessibilityInfo: typeof AccessibilityInfo_default` + the full `AccessibilityInfo_default` type

## Changelog:
[GENERAL] [FIXED] - hash generation includes `declare const` types in API snapshot

Differential Revision: D88653322
@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @emily8rown in c36665f

When will my fix make it into a release? | How to file a pick request?

@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Dec 10, 2025

This pull request has been merged in c36665f.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Dec 10, 2025
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. fb-exported 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