fix: Upgrade @wordpress/format-library and fix PlainText CJS interop#323
fix: Upgrade @wordpress/format-library and fix PlainText CJS interop#323
Conversation
f85d276 to
80ba09d
Compare
| - Allow setting popover props for the `Inserter` component, so we can improve the mobile screen reader experience by marking it as a modal dialog. | ||
| - Prevent the insertion point popover from appearing on touch devices in `InserterListItem`. The popover (triggered by `onMouseEnter`) disrupts tap/click events, requiring users to tap inserter items twice before they are inserted. | ||
| - Fix `PlainText` component crash caused by esbuild's `.mjs` CJS interop wrapping `react-autosize-textarea`'s default export as a module object instead of the actual React component. WordPress packages switched their build output from `.js` to `.mjs` starting in v15.11, which triggers Node-style interop in Vite's dependency pre-bundling. | ||
| - Add `./build-module/components/inserter/media-tab/*` and `./build-module/components/inserter/hooks/*` to the package's `exports` field to allow importing internal inserter modules used by the native inserter component. Note: Creating this patch required using `--exclude='^$'` due to a [patch-package limitation](https://github.com/ds300/patch-package/issues/250). |
There was a problem hiding this comment.
The "Add" line documents a preexisting patch.
Bumps [@wordpress/format-library](https://github.com/WordPress/gutenberg/tree/HEAD/packages/format-library) from 5.36.0 to 5.38.0. - [Release notes](https://github.com/WordPress/gutenberg/releases) - [Changelog](https://github.com/WordPress/gutenberg/blob/trunk/packages/format-library/CHANGELOG.md) - [Commits](https://github.com/WordPress/gutenberg/commits/@wordpress/format-library@5.38.0/packages/format-library) --- updated-dependencies: - dependency-name: "@wordpress/format-library" dependency-version: 5.38.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Regenerate patches for @wordpress/format-library (5.36.0 -> 5.38.0) and @wordpress/block-editor (15.10.0 -> 15.11.0). The underlying fixes are unchanged; only the target versions were updated. The block-editor patch also adds deep module exports for the inserter media-tab and hooks paths.
WordPress packages v15.11+ switched build output from .js to .mjs, which triggers esbuild's Node-style CJS interop during Vite dependency pre-bundling. This caused react-autosize-textarea's default export (a ForwardRef component) to be wrapped as a module object instead of the component itself, crashing the Shortcode block with "type is invalid -- expected a string or class/function but got: object". The patch unwraps the default import when it resolves to a module object. Also adds deep module exports for the inserter media-tab and hooks paths.
80ba09d to
f1f6a07
Compare
…-textarea patch Replace our consumer-side workaround in `@wordpress/block-editor`'s `plain-text/index.mjs` with Gutenberg's upstream patch that fixes the root cause in `react-autosize-textarea` directly. The new patch removes the `__esModule` flag and switches from `exports["default"]` to `module.exports`, preventing Vite's esbuild pre-bundling from wrapping the default export as a module object.
There was a problem hiding this comment.
Regenerate this existing patch to capture Gutenberg's move to ECMAScript modules (ESM) in WordPress/gutenberg#74348.
There was a problem hiding this comment.
Regenerate this existing patch to capture Gutenberg's move to ECMAScript modules (ESM) in WordPress/gutenberg#74348.
There was a problem hiding this comment.
This applies the same patch used by the Gutenberg project to address the following issue.
This is an unfortunate necessity. Without this, inserting blocks that rely upon Gutenberg's PlainText component (e.g., Shortcode, Jetpack AI Assistant) result in a "This block has encountered an error and cannot be previewed" message and an error:
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
Gutenberg's PlainText component relies upon an unmaintained react-autosize-textarea library. Gutenberg has long attempted to drop this dependency. It relies upon CommonJS modules (CJS).
The patch is now required as Gutenberg's recently embraced ECMAScript modules (ESM) in WordPress/gutenberg#74348. Gutenberg's patch was added in WordPress/gutenberg#73822.
With #313, the Shortcode block is now covered by automated E2E tests to ensure this regression is not present.
What?
Upgrade
@wordpress/format-libraryfrom 5.36.0 to 5.38.0 and fix aPlainTextcomponent crash caused by Vite's CJS interop with.mjspackages.Supersedes #285.
Why?
Dependabot bumped
@wordpress/format-libraryto 5.38.0, which also pulled in@wordpress/block-editor@15.11.0. The new.mjsbuild output triggers esbuild's Node-style CJS interop during Vite dependency pre-bundling, causingreact-autosize-textarea's default export (aForwardRefcomponent) to be wrapped as a module object. This crashes the Shortcode block with:How?
@wordpress/format-library(5.36.0 → 5.38.0)@wordpress/format-library5.36.0 → 5.38.0,@wordpress/block-editor15.10.0 → 15.11.0)react-autosize-textareapatch that fixes the CJS interop issue at the source by removing the__esModuleflag and switching fromexports["default"]tomodule.exports. This is the same patch used by the upstream Gutenberg project.Testing Instructions
npm ci— patches should apply cleanlyAccessibility Testing Instructions
No UI changes — this is a dependency upgrade and build fix.