-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Code quality: Replace hardcoded store keys with store definitions #27088
Comments
Hello! Are the unchecked items (except the one in #27094) available for taking? I would like to replace some of these. |
Yes, those unchecked and without a PR referenced are up for grabs 👍
|
Taking |
There is no need to wait. We can always rebase with |
Great! I just asked to make sure I wouldn't be complicating things... 😸 |
I would love to pick up one of these as my inaugural Gutenberg issue, using the other PRs so far as a model for the work. |
Can I take |
@rafaelgalani, whatever works for you best. I added your name next to |
definition Replaces references to the `core/keyboard-shortcuts` store name string with the store definition object, adding `import`s where necessary. Addresses WordPress#27088.
) definition Replaces references to the `core/keyboard-shortcuts` store name string with the store definition object, adding `import`s where necessary. Addresses #27088.
I opened #27368 that removes bare import statements for packages that use now store definitions rather than hardcoded strings. |
Taking |
Oh, that sounds like a fantastic idea! We can also warn people working on new PRs to avoid using strings. |
@aristath, what's the current status after your recent work in this area? I see a few more warnings, are there any issues discovered? We should promote the warning to error as the last step. |
There are just a handful of them remaining, these are the ones I couldn't address (*a couple of them were reverted because they were causing an issue with an e2e test)
gutenberg/packages/edit-post/src/components/header/fullscreen-mode-close/index.js Line 27 in 4c3300c
gutenberg/packages/edit-post/src/store/actions.js Lines 499 to 500 in 4c3300c
Once we address these 6 we should promote this to an error 🎉 |
I started #32537 which tries to tackle the remaining issues. |
We did it 🎉 Amazing team effort everyone involved. Major props for the achievement. There is even an ESLint rule There are still several places where we have hardcoded store names, but they require some architectural changes because the stores used in the code are present conditionally depending on the execution context. There is a group of items to look at raised for the code used with native mobile apps in #27751. In the web part of the universe, we still have two places that need more work: Discovered in #32801: gutenberg/packages/block-library/src/calendar/edit.js Lines 51 to 55 in ee69822
Discovered in #32537 gutenberg/packages/server-side-render/src/index.js Lines 19 to 23 in 58aab25
The related follow-up issue is #32842. |
Description
With #26655 it's possible to use store definitions as param for
select
/useSelect
/withSelect
anddispatch
/useDispatch
/withDispatch
API method calls exposed from@wordpress/data
. It resolves the issue with the need to use unscoped import statements for packages that define stores used as explained in #8981 (comment):The next step is to use newly exposed
store
definitions from the corresponding packages similar to how it was applied to thestore
exposef from@wordpress/viewport
in #26655. Example:The goal is to make it simpler to maintain dependencies between packages to avoid bugs when consuming from npm. The other benefit is that we will prevent cyclic dependencies in the early stages of development.
Tasks
This is the list of store names that should be replaced with their newly introduced store definitions:
core
core/annotation
(Annotations: Replace store name string with exposed store definition #28156 @rafaelgalani)core/block-directory
(Block Directory: Replace store name string with exposed store definition #27178 @rafaelgalani)core/block-editor
core/blocks
(Blocks: Replace store name string with exposed store definition #27336 @rafaelgalani )core/data
core/edit-navigation
(Edit Navigation: Replace store name string with exposed store definition #27182, Edit Navigation: Replace remaining store name string with constant #27281 @rafaelgalani)core/edit-post
(Edit Post: Replace store name string with exposed store definition #27414 @rafaelgalani)core/edit-site
(Site Editor: Replace core/edit-site store name with store object #28695 @david-szabo97)core/edit-widgets
(Edit Widgets: Replace store name string with exposed store definition #28044 @rafaelgalani)core/editor
core/interface
(Interface: Replace store name string with exposed store definition #28041 @rafaelgalani)core/keyboard-shortcuts
(Keyboard Shortcuts: Replace store name string with exposed store definition #27355 @bosconian-dynamics)core/notices
(Code Quality: Use store definition instead of string for notices packages #27548 @gziolo)core/reusable-blocks
(Reusable Blocks: Change from store name provided as a string to store definition #27094 @grzim)core/rich-text
(Rich Text: Replace store name string with exposed store definition #27820 @rafaelgalani)core/viewport
(@gziolo)The text was updated successfully, but these errors were encountered: