-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New block created with @wordpress/scripts@28 don't show up on wordpress #62202
Comments
+1 However if you put the block inside a template html file with it's block name it appears on the front end. |
Thanks for the report. I was able to reproduce this issue. I built the block with scripts version 27 and 28 and found a difference in the contents of version 27.9: <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => 'd97fdb9bbdb79e4913a4'); version 28.0: <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => 'b0e4f78143cfbd1f56d2'); If I manually change this to |
With v28 scripts all my blocks in my custom block theme stop working, was there any drastic change that I had to take into account when moving from 27 to 28? |
Same here, after updating to v28 custom blocks completely disappeared.
reverting to --- edit --- I just noticed that removing those lines: gutenberg/packages/dependency-extraction-webpack-plugin/lib/util.js Lines 46 to 48 in ceb8949
solves the issue. Maybe this is something related to the-new-jsx-transform? |
same problem here. If i replace pacakage-lock.json with 27.9.0 the block works but with 28.0.0 it disappears. |
Same problem here. I downgraded to 27.9.0 to make my blocks work again. |
cc @youknowriad @Mamaduka who worked on / reviewed the original PR. The way it's currently built is not compatible with WP < 6.6 |
The problem is going to exist for quite some time because many plugins target older major versions of WordPress. In WP 6.5 and older there is no |
Thanks for creating the issue and sharing your concern. It's clear that we overlooked a bit the impact of this change. Especially for the create-block package. That said, the solution her is to actually stick to the old version of wp-scripts in the build tooling. Dev Tools and Production dependencies don't need to be updated at the same time. Plugin authors that already have a build tool in place don't need to touch their dependencies. I think there's a couple of things we should do here: 1- First one is to fix @wordpress/create-block and stick to an old version of 2- Write a post on make/core that serves as a dev note quickly to explain the change and the potential impact on build tools. |
@youknowriad might I also suggest updating the CHANGELOG.md file? |
@justlevine The CHANGELOG already mentions the breaking change. Would you like to seem something else there? |
|
If the minimum required WP version is changing to 6.6 (as I understood your comment to mean), this should be noted directly. Even if it was included in the PR description, I'd recommend this - more so since it seems to be a side effect that isnt called out explicitly in #61692 |
It's not just I don't know whether updating the other packages but keeping |
I also had to downgrade |
The same issue is also being discussed on WordPress Slack (link requires registration at https://make.wordpress.org/chat/): https://wordpress.slack.com/archives/C02QB2JS7/p1717340775169699. |
In the same vein, what should package consumers do regarding From some quick testing, it doesn't seem to break anything by itself, at least in our case. |
I've opened #62265 to add a clearer note to the different impacted packages per the discussion above. Thanks for the suggestions. |
To address this issue, it would be nice to create a What is needed is the post install script that parses the package.json and something akin to the In this case if I had specified in my package.json
it should have thrown an error and said it is not compatible with my version of wp What do you think? I think it would be easy to implement and would be extremely beneficial. |
@thelovekesh, I wasn't able to make the polyfill solution work. However, without any extra webpack config, just loading the file from the core directory worked for me in WP 5.5, like so: if ( ! wp_script_is( 'react-jsx-runtime', 'registered' ) ) {
wp_register_script(
'react-jsx-runtime',
'/wp-includes/js/dist/vendor/react-jsx-runtime.js',
array( 'react' ),
'18.2.0',
true
);
} I'm trying to understand what the extra webpack config does and why we need it, since registering these files didn't seem to work in my case. |
WP 5.5 doesn't have the The If possible, you should avoid harcoding |
Somehow this was working for me, but @jsnajdr, thanks for pointing this out, what you say makes sense. |
It seems that many people opt to stay on the old branch instead of adopting a polyfill solution, and I understand that. However, the old branch doesn't receive security updates introduced later, which becomes problematic. @TobiasBg, have you actually managed to make this work? I visited your repo and couldn't find the code. |
Seeing how @acicovic and others struggle with adding a We always encourage people to use the latest version of WordPress and everything related. It should be ok to use the latest version of It's also common that plugins support several versions of WordPress back. Supporting only the very latest version is very rare if not nonexistent. Therefore, the standard version (i.e., the latest) of Creating the I don't know how to solve this yet. Currently the JSX |
Maintaining backward compatibility can be challenging sometime for various reasons. In the current setup, everything should function correctly with the latest version of WordPress and the For those who need it, here is an example of a polyfill implementation: Polyfill Implementation. Additionally, include this PHP code to ensure the polyfill is loaded correctly: PHP Code for Polyfill. |
@thelovekesh, thanks for the links, I'll take a look. In the meantime, for anyone wanting to stay on the older version but get rid of the vulnerabilities, it's possible to add "overrides": {
"puppeteer-core": "^23.1.0"
}, You should test though that this change works well for your project. |
@acicovic: Yes, I have the polyfill code working fine, but unfortunately, it's not yet in a released branch of my plugin, which is why it's not yet in that repo. Sorry :-( But it's pretty much what has been discussed above. |
The code I had written in my attempt to update is already pretty close to the examples I'm seeing here. So I can only assume that there's something specific in my config that doesn't work as expected, and that I can't see it. This is my first time messing with webpack configs, so this doesn't help either. I think that @jsnajdr makes some great points. If many developers are postponing a pollyfil solution, what will happen when we're forced to go that route with React 19? I think there should be some official form of docs for that, and people who can help out on GitHub issues. |
More or less every WordPress plugin aims to support multiple versions, and I think it's not a reasonable ask that more or less everyone should understand the polyfills, be able to implement them themselves, or to be even aware that they are needed. What if the |
I totally agree, this would be very helpful. |
Would the following work for older versions of WordPress defined as an inline JS script with the <script>
globalThis.ReactJSXRuntime = {
jsx: React.createElement,
jsxs: React.createElement,
Fragment: React.Fragment,
};
</script> The alternative would be to copy and adjust the production version, which is 859 bytes: https://unpkg.com/browse/[email protected]/cjs/react-jsx-runtime.production.min.js 'use strict';var f=require("react"),k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};
function q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=""+g);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}exports.Fragment=l;exports.jsx=q;exports.jsxs=q; We could create a PHP file that conditionally enqueues such an inline script. It would live next to the webpack config in |
@gziolo, who would be the person that can give an answer to your question? Asking in case we can relay this to them more directly. |
Almost, but not quite 🙂 The API for createElement( 'div', { className: 'box', key: 'k' }, child1, child2, child3 );
// or
createElement( 'div', { className: 'box', key: 'k' }, [ child1, child2, child3 ] ); while jsx( 'div', { className: 'box', children: [ child1, child2, child3 ] }, 'k' );
// or for a single child
jsx( 'div', { className: 'box', children: child1 }, 'k' ); So, we'd need to do some extra work to implement the new runtime in terms of the old |
@jsnajdr @gziolo Would something like this work? import { createElement, Fragment as ReactFragment } from 'react';
const jsx = ( element, props = {}, key = '' ) => {
let children = [];
if ( props.children ) {
children = Array.isArray( props.children ) ? props.children : [ props.children ];
delete props.children;
}
if ( key ) {
props.key = key;
}
return createElement( element, props, ...children );
};
const jsxs = ( element, props = {}, key = '' ) => {
return jsx( element, props, key );
}
const Fragment = ReactFragment;
globalThis.ReactJSXRuntime = globalThis.ReactJSXRuntime || { jsx, jsxs, Fragment }; |
@peterwilsoncc Yes, but there is one additional caveat where we need to be careful. There is a difference between: <div><br/><br/></div> and <div>{ [ <br/>, <br/> ] }</div> // such array is typically created with a .map In the first syntax the children are "static" and they don't have to have // classic runtime: children are spread
createElement( 'div', null, <br/>, <br/> )
// new runtime: uses jsxs function
jsxs( 'div', { children: [ <br/>, <br/> ] } ) With the second syntax children are checked for presence of a // classic runtime: children are array
createElement( 'div', null, [ <br/>, <br/> ] )
// new runtime: uses jsx function
jsx( 'div', { children: [ <br/>, <br/> ] } ) We need to take this into account when mapping |
Hello! Just wanted to ask if there any news or work on this, also taking into account the recent release of React 19? |
The changes to how JSX is handled were done in anticipation of changes in React 19. There are some other breaking changes coming in React 19, so the impact will have to be assessed separately. |
Description
I tried to create a new plugin / block with create-block and the block is not available in the back-end. There's no build error, php error or javascript error.
Step-by-step reproduction instructions
1 : Create a new wordpress plugin "npx @wordpress/create-block test-plugin"
2: cd test-plugin
3 : npm start
3 : activate plugin test-plugin
4 : edit a new page in wp-admin
5 : try to add the new block "/test-plugin"
6: nothing append
step to correct
Screenshots, screen recording, code snippet
No response
Environment info
Wordpress 6.53.
@wordpress/scripts": "^28.0.0"
node 22.2
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
The text was updated successfully, but these errors were encountered: