Skip to content

metro-file-map: Let plugins report what changed in a batch, on the change event - #2233

Closed
robhogan wants to merge 1 commit into
pr2232from
pr2233
Closed

robhogan wants to merge 1 commit into
pr2232from
pr2233

Conversation

@robhogan

Copy link
Copy Markdown
Collaborator

Context

A file map plugin often knows things about a batch of changes that nothing else can work out. For Haste, #1952 records the names a resolution looked up, and invalidating from those means knowing which names a change rebound. The ChangeEvent carries paths, and by the time a consumer sees it a removed file's name is already gone from the map, but HastePlugin.onChanged has it to hand:

onChanged(delta: ReadonlyFileSystemChanges<?string>): void {
// Process removals first so that moves aren't treated as duplicates.
for (const [canonicalPath, maybeHasteId] of delta.removedFiles) {
this.#onRemovedFile(canonicalPath, maybeHasteId);
}

This change

This lets a plugin's onChanged return a summary, published on ChangeEvent.pluginChanges by plugin name. The summary type defaults to void, so existing plugins are unaffected. HastePlugin reports changedNames.

Plugin names now have to be unique across all plugins, not just those with a worker. Persisted state was already keyed by name, so two sharing a name were already overwriting each other.

Not addressed here: on a cold start HastePlugin builds a summary nobody reads (transient, and nothing where Haste is inert), and an edit that changes a file's Haste name is neither applied to the map nor reported, which predates this.

Invalidating from the summary is the next PR.

Changelog: Internal

Test plan

New unit tests cover the watch and recrawl paths and duplicate plugin names.

…ange event

## Context

A file map plugin often knows things about a batch of changes that nothing else can work out. For Haste, #1952 records the names a resolution looked up, and invalidating from those means knowing which names a change rebound. The `ChangeEvent` carries paths, and by the time a consumer sees it a removed file's name is already gone from the map, but `HastePlugin.onChanged` has it to hand:

https://github.com/react/metro/blob/6dbe97956af0f66f7a1d88014ba0b784a4a4d893/packages/metro-file-map/src/plugins/HastePlugin.js#L241-L245

## This change

This lets a plugin's `onChanged` return a summary, published on `ChangeEvent.pluginChanges` by plugin name. The summary type defaults to `void`, so existing plugins are unaffected. `HastePlugin` reports `changedNames`.

Plugin names now have to be unique across all plugins, not just those with a worker. Persisted state was already keyed by name, so two sharing a name were already overwriting each other.

Not addressed here: on a cold start `HastePlugin` builds a summary nobody reads (transient, and nothing where Haste is inert), and an edit that changes a file's Haste name is neither applied to the map nor reported, which predates this.

Invalidating from the summary is the next PR.

Changelog: Internal

## Test plan

New unit tests cover the watch and recrawl paths and duplicate plugin names.
@robhogan
robhogan added this pull request to stack #2234 November 16, 2026 16:17
@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 Nov 16, 2026
@robhogan
robhogan removed this pull request from stack #2234 November 16, 2026 16:18
@robhogan

Copy link
Copy Markdown
Collaborator Author

Opened by mistake, duplicate of #1953

@robhogan robhogan closed this Nov 16, 2026
@robhogan
robhogan deleted the pr2233 branch November 16, 2026 16:18
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant