Skip to content

Components: Key useBaseControlProps ids on the hook, not BaseControl - #86322

Merged
retrofox merged 5 commits into
trunkfrom
fix/base-control-hooks-circular-import
Nov 5, 2026
Merged

retrofox merged 5 commits into
trunkfrom
fix/base-control-hooks-circular-import

Conversation

@retrofox

@retrofox retrofox commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What?

useBaseControlProps keys the generated id on the hook itself instead of on BaseControl, and hooks.ts no longer imports BaseControl at all.

Why?

hooks.ts imported BaseControl from ./index, the module that re-exports the hook, so the two files import each other. The ESM build handles that cycle through live bindings. The CommonJS build does not: build/base-control/hooks.cjs requires ./index.cjs and wraps the result with __toESM() while index.cjs is still loading, so its default is copied as undefined.

Every CommonJS consumer rendering a control built on the hook without an id, such as ToggleGroupControl and the DataViews view options that use it, then calls useInstanceId( undefined ) and crashes with TypeError: Invalid value used as weak map key. With an id the hook returns it before touching its map, so those renders survive.

See #86328 for the Rolldown regression behind the CommonJS output.

How?

useInstanceId only needs a stable object to key its counter on, so the hook function serves as well as the component. The wp-components-base-control prefix is unchanged, so the ids keep their shape. Dropping the import also removes the cycle itself.

Testing Instructions

Build the packages, then render the control from the CommonJS build in plain Node, from the package directory so react resolves:

npm run build
cd packages/components
node -e "
const React = require( 'react' );
const { renderToString } = require( 'react-dom/server' );
const { __experimentalToggleGroupControl: ToggleGroupControl, __experimentalToggleGroupControlOption: Option } = require( './build/index.cjs' );
console.log( renderToString( React.createElement( ToggleGroupControl, { label: 'Size', value: 'a', __nextHasNoMarginBottom: true, __next40pxDefaultSize: true }, React.createElement( Option, { value: 'a', label: 'A' } ) ) ).slice( 0, 60 ) );
"

On trunk, this throws TypeError: Invalid value used as weak map key. With this change, it prints the rendered markup. Passing an id to the control makes trunk render too, which is why the snippet leaves it out.

The unit tests for the control cover the generated ids:

npm run test:unit -- packages/components/src/base-control packages/components/src/toggle-group-control

The hook imported BaseControl from the package entry that re-exports the hook. In the CommonJS build that circular import resolves to undefined, so every control built on useBaseControlProps, ToggleGroupControl among them, crashed with "Invalid value used as weak map key". The ESM build was unaffected.
@retrofox
retrofox requested a review from a team as a code owner November 4, 2026 17:24
@retrofox retrofox added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Nov 4, 2026
@retrofox retrofox self-assigned this Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: retrofox <retrofox@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: 0 B

Total Size: 8.61 MB

5ddd2da Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 13f2fcb trunk % Change
timeToFirstByte 56.8 ms +6.07% -5.55% 57.35 ms +10.72% -7.15% -0.96%
largestContentfulPaint 92 ms +6.52% -4.35% 92 ms +8.7% -4.35% 0%
lcpMinusTtfb 35.15 ms +16.5% -3.7% 35.05 ms +5.99% -7.56% 0.29%
wpBeforeTemplate 29.38 ms +14.33% -2.93% 29.47 ms +16.56% -4.68% -0.31%
wpTemplate 22.15 ms +3.3% -4.97% 22.46 ms +4.14% -4.99% -1.38%
wpTotal 52.65 ms +6.88% -5.19% 53.38 ms +10.4% -7.25% -1.37%
wpMemoryUsage 7.72 MB +0% -0% 7.68 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 13f2fcb trunk % Change
timeToFirstByte 46.5 ms +3.76% -2.15% 46.65 ms +7.72% -2.14% -0.32%
largestContentfulPaint 100 ms +4% -0% 100 ms +4% -0% 0%
lcpMinusTtfb 54.05 ms +1.94% -2.5% 53.65 ms +1.3% -1.77% 0.75%
wpBeforeTemplate 26.61 ms +2.37% -2.78% 26.33 ms +9.49% -1.86% 1.06%
wpTemplate 16.37 ms +6.54% -2.14% 17.1 ms +1.11% -4.74% -4.27%
wpTotal 43.35 ms +4.27% -1.96% 43.54 ms +7.33% -2.3% -0.44%
wpMemoryUsage 6.41 MB +0% -0% 6.37 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 13f2fcb trunk % Change
mediaProcessingJpeg 400.3 ms +1.01% -0.48% 397.8 ms +2.29% -0.67% 0.63%
mediaProcessingAvif 6148.39 ms +0.34% -0.33% 6131.38 ms +0.46% -0.19% 0.28%
mediaProcessingJpegToAvif 4249.75 ms +0.15% -0.34% 4236.28 ms +0.27% -0.12% 0.32%

media-upload

Metric 13f2fcb trunk % Change
jpegUploadProcessing 1463.47 ms +2.92% -0.07% 1472.97 ms +0.67% -0.91% -0.64%
pngUploadProcessing 170.45 ms +19.07% -4.42% 209.77 ms +22.11% -15.07% -18.74%
largeJpegUploadProcessing 1465.17 ms +31.82% -0.93% 1460.96 ms +1.97% -1.01% 0.29%
multipleImageUploadProcessing 2046.61 ms +0.93% -0.98% 2009.93 ms +0.82% -5.14% 1.82%

post-editor

Metric 13f2fcb trunk % Change
serverResponse 453.02 ms +7.15% -5.18% 459.03 ms +4.76% -5.28% -1.31%
firstPaint 415.84 ms +16.34% -21.69% 375.33 ms +29.16% -7.65% 10.79%
domContentLoaded 852.42 ms +2.6% -1.55% 844.48 ms +3.07% -0.76% 0.94%
loaded 853.52 ms +2.58% -1.57% 845.52 ms +3.07% -0.79% 0.95%
firstContentfulPaint 496.22 ms +4.53% -2.56% 486.72 ms +4.43% -2.23% 1.95%
firstBlock 2166.81 ms +0.8% -0.79% 2168.69 ms +0.24% -0.17% -0.09%
type 18.31 ms +7.7% -13.49% 17.85 ms +5.1% -3.47% 2.58%
typeWithoutInspector 17.99 ms +4.84% -8.73% 17.52 ms +6.96% -7.93% 2.68%
typeWithTopToolbar 24.44 ms +3.52% -8.96% 23.38 ms +12.7% -5.22% 4.53%
typeContainer 7.84 ms +10.08% -1.79% 8.19 ms +11.84% -5.37% -4.27%
focus 120.94 ms +2.94% -1.6% 115.41 ms +2.44% -2.11% 4.79%
firstFocus 262.58 ms +0% -0% 258.94 ms +0% -0% 1.41%
selectAll 399.34 ms +0.92% -2.16% 431.7 ms +2.69% -4.76% -7.5%
undo 29.13 ms +6.66% -6.08% 28.91 ms +6.57% -7.58% 0.76%
listViewOpen 79.82 ms +4.11% -8.97% 75.4 ms +15% -3.87% 5.86%
inserterOpen 43.67 ms +2.29% -5.27% 41.47 ms +3.09% -5.67% 5.31%
inserterHover 10.91 ms +10.27% -9.07% 10.81 ms +12.12% -11.19% 0.93%
inserterSearch 9 ms +6.11% -9% 8.16 ms +9.44% -10.17% 10.29%
loadPatterns 629.62 ms +7.8% -6.62% 623.1 ms +9.06% -1.1% 1.05%
wpTotal 442.73 ms +7.42% -5.15% 449.09 ms +4.88% -5.31% -1.42%
wpMemoryUsage 14.76 MB +0% -0% 14.73 MB +0% -0% 0.24%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 13f2fcb trunk % Change
serverResponse 461.17 ms +1.72% -5.28% 465.4 ms +0.74% -0.81% -0.91%
firstPaint 360.06 ms +24.87% -3.18% 359.91 ms +5.24% -15.04% 0.04%
domContentLoaded 870.32 ms +4.6% -1.25% 853.01 ms +2.14% -1.09% 2.03%
loaded 871.36 ms +4.61% -1.26% 854.1 ms +2.14% -1.1% 2.02%
firstContentfulPaint 502.81 ms +9.41% -5.98% 492.97 ms +4.02% -2.04% 2%
firstBlock 2582.18 ms +5.47% -2.1% 2540.61 ms +1.13% -0.81% 1.64%
type 18.23 ms +10.37% -10.59% 18.66 ms +7.5% -6.11% -2.3%
navigate 118.79 ms +0.92% -7.48% 114.4 ms +6.6% -2.23% 3.84%
loadPatterns 1313.91 ms +4.72% -5.26% 1260.14 ms +8.9% -14.6% 4.27%
loadPages 1000.36 ms +2.28% -4.78% 978.21 ms +1.59% -3.4% 2.26%
wpTotal 451.54 ms +1.69% -5.42% 455.44 ms +0.87% -0.69% -0.86%
wpMemoryUsage 12.78 MB +0% -0% 12.74 MB +0% -0% 0.27%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

5ddd2da Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 6,
+   "offset": 6,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
should keep correct selection when dragging outside block (-firefox) in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 2 failed attempts.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

  Array [
    Object {
      "attributes": Object {
-       "content": "1",
+       "content": "23",
      },
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:787:41
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

  Array [
    Object {
      "attributes": Object {
-       "content": "1",
+       "content": "23",
      },
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:787:41
should partially select with shift + click in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  -  1
+ Received  + 11

  Array [
    Object {
      "attributes": Object {
-       "content": "<strong>1</strong>|2",
+       "content": "<strong>1</strong>[",
+       "dropCap": false,
+     },
+     "innerBlocks": Array [],
+     "name": "core/paragraph",
+   },
+   Object {
+     "attributes": Object {
+       "content": "]2",
+       "dropCap": false,
      },
+     "innerBlocks": Array [],
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:1600:41
should re-trigger autocomplete when backspacing into a completed mention in /test/e2e/specs/editor/various/autocomplete-and-mentions.spec.js, passed after 2 failed attempts.
Error: apiRequestContext.fetch: socket hang up
Call log:
  - → DELETE http://localhost:8891/wp-json/wp/v2/users/14?force=true&reassign=1
    - user-agent: Playwright/1.63.0 (x64; ubuntu 24.04) node/24.20 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br
    - X-WP-Nonce: 522197a7ae
    - cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_da433b7faafd8180ebeb1624ceeeab7e=admin%7C1794042657%7CTaOTtqnYThNZ7gP6dhOTCfy9VL7VDcnVuElNQ95dLiB%7Cd29ad5a4e7ab738ddd7ccc0b22d77b1adab006ce4c202001e96cf021847490e7; wp-settings-time-1=1793869995

    at RequestUtils.rest (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/rest.ts:111:39)
    at RequestUtils.deleteUser (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/users.ts:91:30)
    at map (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/users.ts:116:51)
    at RequestUtils.deleteAllUsers (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/users.ts:116:5)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/autocomplete-and-mentions.spec.js:73:3

5ddd2da Run

Co-authored-by: retrofox <77539+retrofox@users.noreply.github.com>

@mirka mirka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reporting 🙏 This looks like a regression from #85476. I opened a broader issue at #86328.

The testing steps don't run as written. There's no build:packages script, and require( 'react' ) fails from the repo root. But more importantly the crash also only seems to happen when no id is passed, which is worth noting.

Comment thread packages/components/CHANGELOG.md Resolved
retrofox and others added 2 commits November 5, 2026 08:45
Co-authored-by: Lena Morita <lena@jaguchi.com>
Co-authored-by: Lena Morita <lena@jaguchi.com>
Comment thread packages/components/CHANGELOG.md Outdated

### Bug Fixes

- `useBaseControlProps`: Fix a crash in the CommonJS build when no `id` is passed, which also affected controls built on the hook such as `ToggleGroupControl` ([#86322](https://github.com/WordPress/gutenberg/pull/86322)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would word this differently:

  • useBaseControlProps: fix instance ID generation crash in CommonJS build by avoiding a circular import of BaseControl.

Current Claude models have a weird and incomprehensible writing style when it comes to code comments and changelog entries. I roll my eyes over them all the time 🙂 Hope it gets better soon.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for feedback. Updated.

@retrofox

retrofox commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reporting 🙏 This looks like a regression from #85476. I opened a broader issue at #86328.

👍. Added the issue to the PR desc

The testing steps don't run as written. There's no build:packages script, and require( 'react' ) fails from the repo root. But more importantly the crash also only seems to happen when no id is passed, which is worth noting.

Updated

Fix instance ID generation crash in CommonJS build by avoiding a circular import of BaseControl.
@retrofox
retrofox merged commit c243ab2 into trunk Nov 5, 2026
86 checks passed
@retrofox
retrofox deleted the fix/base-control-hooks-circular-import branch November 5, 2026 09:38
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 5, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
…ordPress#86322)

* Components: Key useBaseControlProps ids on the hook, not BaseControl

The hook imported BaseControl from the package entry that re-exports the hook. In the CommonJS build that circular import resolves to undefined, so every control built on useBaseControlProps, ToggleGroupControl among them, crashed with "Invalid value used as weak map key". The ESM build was unaffected.

* Add PR link to components changelog entry

Co-authored-by: retrofox <77539+retrofox@users.noreply.github.com>

* Update packages/components/src/base-control/hooks.ts

Co-authored-by: Lena Morita <lena@jaguchi.com>

* Update packages/components/CHANGELOG.md

Co-authored-by: Lena Morita <lena@jaguchi.com>

* Fix crash in useBaseControlProps for CommonJS build

Fix instance ID generation crash in CommonJS build by avoiding a circular import of BaseControl.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: retrofox <77539+retrofox@users.noreply.github.com>
Co-authored-by: Lena Morita <lena@jaguchi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants