-
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
Added support for React.version
in the @wordpress/element package
#49312
base: trunk
Are you sure you want to change the base?
Conversation
I almost feel like adding a version number to this package is a bandaid for a larger problem of gutenberg + wpjs package management throughout the different wordpress environments / sections / tools. Also, to me it would make sense to use |
@margolisj While the initial issue deals with the BUT you're also not wrong that it'd be nice if |
As well as the reasons already outlined I just like the idea of having easy access to the current version of React on the WordPress site I'm working on. So, being able to just open a console window and enter Also, I find it a little disorienting that there's no super simple for users to check the version of React via the Gutenberg editor UI. I'd personally find it useful to have this displayed somewhere. Not sure where it would be best to add this but here's what it could look like in the Preferences modal. |
/** | ||
* Current version of React. | ||
*/ | ||
export { version }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider calling it reactVersion
or ReactVersion
. Mere version
suggests that it's the version of @wordpress/element
, which it isn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qualifying it makes sense to me.
I don't know how I feel about the version being added to the UI. 1) that's not really in scope for this particular PR, and 2) I don't actually think that makes sense for the UI, maybe only if |
We discussed this back when working on the React 18 upgrade, and decided in favor of simply re-exporting the raw React APIs. You can read the discussion between #46467 (comment) and #46467 (comment). Implementing the compatible |
Just a general comment, not intended for this PR. |
Very good points! And I totally agree, upon further reflection. I know there's usually good discussions around this, thanks for linking to them! |
What?
Fixes #49308.
Include
version
as part of@wordpress/element
.Why?
Currently, you have to reference this from React directly.
import { version } from "react";
Now that WordPress 6.2 uses React 18, it can be necessary to check against the current version of React to avoid compatibility issues. See the associated issue: #49308
So this code:
becomes
How?
React.version
is imported from React and included in the exported items in@wordpress/element
.Testing Instructions
Go to any page and in the console enter:
wp.element.version
.Screenshots or screencast