gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

WP 6.6 RC1: plugin breaks after update

Open elzadj opened this issue 1 year ago • 4 comments

Description

Plugin: https://wordpress.org/plugins/maxi-blocks/ GitHub: https://github.com/maxi-blocks/maxi-blocks

After updating to WP 6.6 RC 1 we're getting this in the editor:

Uncaught TypeError: Cannot read properties of undefined (reading 'mark')
    at ./src/extensions/store/resolvers.js (resolvers.js:4:22)
    at __webpack_require__ (bootstrap:19:1)
    at ./src/extensions/store/index.js (controls.js:37:24)
    at __webpack_require__ (bootstrap:19:1)
    at ./src/extensions/index.js (isInSiteEditorPreviewIframe.js:8:43)
    at __webpack_require__ (bootstrap:19:1)
    at ./src/index.js (index.js:18:28)
    at __webpack_require__ (bootstrap:19:1)
    at startup:4:92
    at __webpack_require__.O (chunk loaded:25:1)
react-dom.development.js:86 Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client".

Switching back to WP 6.5.5 immediately fixes it, we suspect that it's somehow connected to https://make.wordpress.org/core/2024/06/06/jsx-in-wordpress-6-6/ and maybe to our babel config and / or webpack.config.js

https://github.com/maxi-blocks/maxi-blocks/blob/master/.babelrc.js https://github.com/maxi-blocks/maxi-blocks/blob/master/webpack.config.js

Any help with fixing it is appreciated.

Step-by-step reproduction instructions

  1. Just update to WP 6.6 RC1

Screenshots, screen recording, code snippet

No response

Environment info

React 18.3.1 Node v20.11.1 PHP 8.2.20

If you’re using the JSX syntax in your code base, and as long as you don’t update your dev dependencies (including @wordpress/scripts, @wordpress/babel-preset-default or @wordpress/dependency-extraction-webpack-plugin), you will continue to use the old JSX transform. This will allow your plugin and built files to be compatible with WordPress 6.5, earlier versions and WordPress 6.6 as well.

No packages were updated, here are the versions:

├── @babel/[email protected] ├── @babel/[email protected] ├── @babel/[email protected] ├── @babel/[email protected] ├── @babel/[email protected] ├── @floating-ui/[email protected] ├── @langchain/[email protected] ├── @loadable/[email protected] ├── @prettier/[email protected] ├── @uiw/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── @wordpress/[email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

elzadj avatar Jun 27 '24 12:06 elzadj

I'm experiencing this as well.

Something as simple as this causes this same error to occur:

async function testing() {
    return true;
}

function App() {
    useEffect( () => {
        testing();
    }, [] );
    
    return null;
}

This results in the following error: Uncaught TypeError: Cannot read properties of undefined (reading 'mark')

UPDATE - managed to fix this. We had wp-polyfill loading on the page that was causing this error. Removed the code requiring that dep and all is well.

tomusborne avatar Jun 27 '24 16:06 tomusborne

UPDATE - managed to fix this. We had wp-polyfill loading on the page that was causing this error. Removed the code requiring that dep and all is well.

Thanks for your help! I can confirm that the cause of the Uncaught TypeError: Cannot read properties of undefined (reading 'mark') is indeed the wp-polyfill script, or something connected to it.

It comes from build/index.asset.php dependency by default.

However, our custom blocks don't work.

and we still get

Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client".
  | printWarning | @ | react-dom.development.js:86
-- | -- | -- | --
  | error | @ | react-dom.development.js:60
  | createRoot$1 | @ | react-dom.development.js:29846
  | initializeEditor | @ | edit-post.js?ver=67d…9060f223df7e7e:3312
  | (anonymous) | @ | post.php?post=396406&action=edit:2084

The error comes from the file edit-post.js, from the line const root = (0,external_wp_element_namespaceObject.createRoot)(target); , I see it even with all the plugins deactivated:

/**
 * Initializes and returns an instance of Editor.
 *
 * @param {string}  id           Unique identifier for editor instance.
 * @param {string}  postType     Post type of the post to edit.
 * @param {Object}  postId       ID of the post to edit.
 * @param {?Object} settings     Editor settings object.
 * @param {Object}  initialEdits Programmatic edits to apply initially, to be
 *                               considered as non-user-initiated (bypass for
 *                               unsaved changes prompt).
 */
function initializeEditor(id, postType, postId, settings, initialEdits) {
  const isMediumOrBigger = window.matchMedia('(min-width: 782px)').matches;
  const target = document.getElementById(id);
  const root = (0,external_wp_element_namespaceObject.createRoot)(target);
  (0,external_wp_data_namespaceObject.dispatch)(external_wp_preferences_namespaceObject.store).setDefaults('core/edit-post', {
    fullscreenMode: true,
    themeStyles: true,
    welcomeGuide: true,
    welcomeGuideTemplate: true
  });
  (0,external_wp_data_namespaceObject.dispatch)(external_wp_preferences_namespaceObject.store).setDefaults('core', {
    allowRightClickOverrides: true,
    editorMode: 'visual',
    fixedToolbar: false,
    hiddenBlockTypes: [],
    inactivePanels: [],
    openPanels: ['post-status'],
    showBlockBreadcrumbs: true,
    showIconLabels: false,
    showListViewByDefault: false,
    isPublishSidebarEnabled: true
  });
  (0,external_wp_data_namespaceObject.dispatch)(external_wp_blocks_namespaceObject.store).reapplyBlockTypeFilters();

elzadj avatar Jun 28 '24 09:06 elzadj

After some digging, managed to find this:

  1. Regarding Uncaught TypeError: Cannot read properties of undefined (reading 'mark') and polyfill: looks like @babel/preset-env doesn't really work with WP 6.6 RC1. I've tried the latest release and the latest alpha versions of the package, but ended up removing it from .babelrc.js - that fixed the error, and now our custom blocks work, aside of the point 2 problems:
  2. Regarding Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client". - this warning shows for createRoot that we import from @wordpress/element package, I've tried versions 6.2.0 and 5.35.0 - they both show that error for import { createRoot } from '@wordpress/element'; .
    I also see that error with all plugins deactivated, with 2024 theme, on a new page (note: I have scripts debug enabled): Screenshot from 2024-06-29 10-32-08

elzadj avatar Jun 29 '24 07:06 elzadj

FWIW, the You are importing createRoot from "react-dom" which is not supported warning is a known issue in Gutenberg itself and not caused by other plugins or anything. AFAIK it has to do with the way React is bundled in @wordpress/element. You can safely ignore this warning. (It's just a warning, not an error)


As for the other issue at hand, it is indeed related to wp-polyfill. For context, as noted in this dev note, the wp-polyfill dependency is no longer included by default in WordPress, as it is only relevant for when you are targeting older browsers.

Specifically, you are using generator functions in your code base while still targeting abandoned browsers like IE 11 that do not support generators.

To address this, you need to either manually load the wp-polyfill dependency or you simply remove this line here in your Babel config:

https://github.com/maxi-blocks/maxi-blocks/blob/6a47440d6a6eb8952f416ab8983397f245515f60/.babelrc.js#L23

Your Babel config in general contains polyfills for things that have been added to browsers a long time ago. Those polyfills have long been deprecated because of that. You can basically remove all of them. I recommend just using @wordpress/babel-preset-default

swissspidy avatar Jul 01 '24 07:07 swissspidy

To address this, you need to either manually load the wp-polyfill dependency

Thanks for your help, now most of our custom blocks work, aside of blocks that use typesense-instantsearch-adapter. We are getting the same .mark error for lines like this one https://github.com/typesense/typesense-instantsearch-adapter/blob/20d7d9616a7829f87d806c73653dacef8e5d3fca/lib/SearchRequestAdapter.js#L478

But I guess that's a question for typesense devs, going to create an issue there.

elzadj avatar Jul 01 '24 11:07 elzadj

Looks like https://github.com/typesense/typesense-instantsearch-adapter/issues/112 applies to you

In short: This script was built targeting older browsers such as IE11, where generators were not supported. It thus requires the regenerator runtime to be available (which wp-polyfill provides). You can either manually load wp-polyfill to make it available or try to follow the steps mentioned in that issue to load the script from source and let your webpack config do the bundling. That might be as simple as this:

-import TypesenseInstantSearchAdapter from 'typesense-instantsearch-adapter';
+import TypesenseInstantSearchAdapter from 'typesense-instantsearch-adapter/src/TypesenseInstantsearchAdapter.js';

swissspidy avatar Jul 01 '24 11:07 swissspidy

@elzadj Quick follow-up after looking into it again: I of course meant regenerator-runtime would need to be added manually, not wp-polyfill.

swissspidy avatar Jul 03 '24 12:07 swissspidy

I ran into this issue on a plugin as well even though that plugin uses @wordpress/dependency-extraction-webpack-plugin and, through that, was including wp-polyfill as a script dependency (and FWIW I confirmed that the wp-polyfill script was successfully being loaded in source HTML).

I couldn't find a path to resolution, so I had to update the plugin's browserslist in order to get it working again.

mboynes avatar Jul 10 '24 20:07 mboynes

Yeah if you target Internet Explorer (which is abandoned) then you would include the regenerator code for no reason and would need to manually add regenerator-runtime as a dependency (instead of wp-polyfill -- the latest version of @wordpress/dependency-extraction-webpack-plugin fixes that for you). But just updating the browserslist config makes so much more sense and your users will be thankful for the smaller bundles :)

swissspidy avatar Jul 10 '24 20:07 swissspidy

updated the @wordpress/dependency-extraction-webpack-plugin to version 6.3.0 solve the issue.

https://www.npmjs.com/package/@wordpress/dependency-extraction-webpack-plugin/v/6.3.0

thanks!

FauzanEdris avatar Jul 18 '24 05:07 FauzanEdris

The Pods Plugin is also affected by this problem and its minified code. How can i fix it manually with this wp-polyfill issue ? contacting Pods Author is no option as their support is dead

yonnic avatar Jul 18 '24 11:07 yonnic

@yonnic Their support is well and alive and they are working on this. See https://wordpress.org/support/topic/pods-not-working-with-wordpress-6-6-update/.

swissspidy avatar Jul 18 '24 12:07 swissspidy

@swissspidy Is there any update about this issue?

FWIW, the You are importing createRoot from "react-dom" which is not supported warning is a known issue in Gutenberg itself and not caused by other plugins or anything. AFAIK it has to do with the way React is bundled in @wordpress/element. You can safely ignore this warning. (It's just a warning, not an error)

rilwis avatar Sep 10 '24 04:09 rilwis

AFAIK it is supposed to be fixed in 6.7

swissspidy avatar Sep 10 '24 06:09 swissspidy