Skip to content

Move WPBlockSelection to a single canonical location in block-editor#77864

Closed
Copilot wants to merge 4 commits into
trunkfrom
copilot/sub-pr-77862
Closed

Move WPBlockSelection to a single canonical location in block-editor#77864
Copilot wants to merge 4 commits into
trunkfrom
copilot/sub-pr-77862

Conversation

Copilot AI commented May 1, 2026

Copy link
Copy Markdown
Contributor

The WPBlockSelection type was duplicated across four locations (core-data/src/types.ts, block-editor/src/store/selectors.js, block-editor/src/store/actions.js, editor/src/store/selectors.js) with a @todo to consolidate it. This PR implements that consolidation.

Canonical Location

packages/block-editor/src/store/types.ts (new file) — both core-data and editor already depend on @wordpress/block-editor, so importing from there introduces no new dependencies or circular refs. block-editor semantically owns the selection concept.

Changes

  • Created packages/block-editor/src/store/types.ts exporting the single canonical WPBlockSelection and WPSelection TypeScript interfaces
  • Updated block-editor/tsconfig.json to include the new types.ts file
  • Updated core-data/src/types.ts to re-export both types from @wordpress/block-editor/src/store/types instead of defining them inline (removes the @todo comment)
  • Updated block-editor/src/store/selectors.js, block-editor/src/store/actions.js, and editor/src/store/selectors.js to replace @typedef {Object} WPBlockSelection declarations with @typedef {import(...).WPBlockSelection} references pointing to the canonical file

There is now exactly one interface WPBlockSelection declaration in the repository.

Notes

During implementation, the WPSelection typedef previously in actions.js was found to describe a genuinely different type ({ start, end } for action payloads) versus the canonical WPSelection ({ selectionStart, selectionEnd } for stored state). The selectionChange() function now uses an inline {start: WPBlockSelection, end: WPBlockSelection} type annotation to avoid the naming confusion.

dmsnell and others added 2 commits April 30, 2026 16:59
…ckages.

The `WPBlockSelection` type is more complicated than it may seem at face value.
This change expands the docblock information on the type and links together the
currently-existing duplicates in other packages, which are duplicated to avoid
creating circular dependencies.

This is prepartory work for #77658, but stands on its own as a clarifying update.
Copilot AI changed the title [WIP] Clarify WPBlockSelection type and link to duplicates in other packages Identify canonical home for WPBlockSelection and provide migration plan May 1, 2026
Copilot AI requested a review from dmsnell May 1, 2026 00:08
Copilot finished work on behalf of dmsnell May 1, 2026 00:08
@dmsnell dmsnell force-pushed the rtc/explain-wp-selection-dynamics branch from 58ec519 to d61e793 Compare May 1, 2026 00:13
@dmsnell

dmsnell commented May 1, 2026

Copy link
Copy Markdown
Member

@copilot go ahead and start the work. what is the best new canonical location for the WPBlockSelection type?

you will need to actually add export type lines and look for places that WPBlockSelection is currently being used, either by explicit import or implicitly by existing within the same file as a JS DocBlock @typedef.

when this is done, only a single declaration for the type will exist. if you have multiple copies leftover in the repo then you are not finished. keep going.

Copilot AI commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot go ahead and start the work. what is the best new canonical location for the WPBlockSelection type?

you will need to actually add export type lines and look for places that `WPBlockSel...

Done in commit 0f94b13. Here's what was done:

Canonical location: packages/block-editor/src/store/types.ts (new file) — chosen because core-data and editor already depend on block-editor, making it the right dependency layer with no new circular dependencies.

Changes:

  • Created packages/block-editor/src/store/types.ts with the single canonical WPBlockSelection and WPSelection TypeScript interfaces
  • Added it to block-editor/tsconfig.json's files array
  • Updated core-data/src/types.ts to re-export both types from @wordpress/block-editor/src/store/types (removes the @todo)
  • Replaced the @typedef {Object} WPBlockSelection blocks in block-editor/src/store/selectors.js, block-editor/src/store/actions.js, and editor/src/store/selectors.js with @typedef {import(...).WPBlockSelection} references pointing to the canonical file

One finding during implementation: the WPSelection typedef that was in actions.js actually described a different shape ({ start, end }) than the canonical WPSelection ({ selectionStart, selectionEnd }). These are genuinely different types — one is an action payload format, the other is the stored selection state format. The actions.js version was removed; the selectionChange() function now uses an inline {start: WPBlockSelection, end: WPBlockSelection} type annotation instead.

Copilot AI changed the title Identify canonical home for WPBlockSelection and provide migration plan Move WPBlockSelection to a single canonical location in block-editor May 1, 2026
Copilot finished work on behalf of dmsnell May 1, 2026 00:31
@dmsnell dmsnell force-pushed the rtc/explain-wp-selection-dynamics branch from d61e793 to c67e682 Compare May 1, 2026 01:22
@dmsnell

dmsnell commented May 1, 2026

Copy link
Copy Markdown
Member

@copilot update based on the updates to the original PR

Copilot AI commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot update based on the updates to the original PR

Updated in commit 099396e. The base branch added extended documentation for the attributeKey property (explaining the multiline attribute case and the data-wp-block-attribute-key DOM attribute). Since the canonical definition now lives in block-editor/src/store/types.ts, I've pulled that expanded doc directly into the canonical file there.

Copilot finished work on behalf of dmsnell May 1, 2026 01:27
@dmsnell

dmsnell commented May 1, 2026

Copy link
Copy Markdown
Member

@copilot monitor the discussion in WordPress.org’s Slack team

https://wordpress.slack.com/archives/C02QB2JS7/p1777595987225769

If someone answers, update this PR

Copilot finished work on behalf of dmsnell May 1, 2026 01:31
@github-actions github-actions Bot added [Package] Core data /packages/core-data [Package] Editor /packages/editor [Package] Block editor /packages/block-editor labels May 1, 2026
@dmsnell dmsnell force-pushed the rtc/explain-wp-selection-dynamics branch 2 times, most recently from 11dd3f3 to 9b5b867 Compare May 4, 2026 01:37
Base automatically changed from rtc/explain-wp-selection-dynamics to trunk May 4, 2026 17:49
@dmsnell dmsnell closed this May 4, 2026
@dmsnell dmsnell deleted the copilot/sub-pr-77862 branch May 4, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] Core data /packages/core-data [Package] Editor /packages/editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants