Skip to content
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

Edit Post: Replace store name string with exposed store definition #27414

Conversation

rafaelgallani
Copy link
Contributor

@rafaelgallani rafaelgallani commented Dec 1, 2020

Description

Addresses #27088. Replaces the store names (hardcoded strings) with the exposed store definitions.

How has this been tested?

npm run test and npm run test-e2e, making sure the tests didn't break.

Types of changes

Code refactoring, non-breaking change.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@rafaelgallani
Copy link
Contributor Author

There are still some references remaining, but most of them are in the e2e-tests and e2e-tests-utils packages. What should I do in these cases? Adding edit-post as a dependency doesn't look right.

There's also selectors.js in edit-post package, which I didn't change since it's not in a select/useSelect/withSelect/dispatch/useDispatch/withDispatch call. Should I change it anyway?

Copy link
Contributor Author

@rafaelgallani rafaelgallani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some stable tests (according to the last runs in the master branch) were failing. I reviewed and found some copy/paste mistakes. I'll fix them and see if it fixes the failing tests.

packages/edit-post/src/store/actions.js Outdated Show resolved Hide resolved
@gziolo gziolo added [Type] Code Quality Issues or PRs that relate to code quality [Package] Edit Post /packages/edit-post labels Dec 1, 2020
@rafaelgallani
Copy link
Contributor Author

In this case, how should I perform these changes? Should I rebase my branch or should I add one more commit on top of it?
I would prefer rebasing + force pushing to keep the commit history clean. I couldn't find recommendations for this situation in the git guidelines.

@rafaelgallani rafaelgallani force-pushed the refactor/replace-edit-post-store-name-with-definition branch from 45c0692 to bda42e4 Compare December 2, 2020 03:27
@rafaelgallani
Copy link
Contributor Author

Rebasing on upstream/master.

@rafaelgallani rafaelgallani force-pushed the refactor/replace-edit-post-store-name-with-definition branch from bda42e4 to a2bb533 Compare December 2, 2020 14:36
@rafaelgallani rafaelgallani marked this pull request as draft December 2, 2020 14:58
@rafaelgallani rafaelgallani force-pushed the refactor/replace-edit-post-store-name-with-definition branch from a2bb533 to e728d8c Compare December 2, 2020 17:07
@rafaelgallani
Copy link
Contributor Author

rafaelgallani commented Dec 2, 2020

At first, the build failed because I forgot to include @wordpress/edit-post in the package.json of each changed package.
I thought that because of this:

To be clear, all packages that use a given datastore should import it in the entry point by convention. It's something that could be improved because if it's missed, it might indeed cause errors. At the moment, there is no simple way to validate it happens. Example:

import '@wordpress/core-data';
import '@wordpress/block-editor';
import '@wordpress/editor';

They already declared it... But anyway. That is fixed now.
The problem now looks like a cyclic dependency problem... Though I'm not sure of it. That is what I could understand by looking at the stack in the action's log:

FAIL packages/block-library/src/list/test/edit.native.js
  ● Test suite failed to run

    TypeError: Cannot read property 'SETTINGS_DEFAULTS' of undefined



 ---> at Object.SETTINGS_DEFAULTS (packages/block-editor/src/index.js:24:22)
      at Object.<anonymous> (packages/editor/src/store/defaults.js:25:5)
      at Object.<anonymous> (packages/editor/src/store/reducer.js:15:1)
      at Object.<anonymous> (packages/editor/src/store/reducer.native.js:14:1)
      at Object.<anonymous> (packages/editor/src/store/index.js:10:1)
      at Object.<anonymous> (packages/editor/src/index.native.js:13:1)
      at Object.<anonymous> (packages/edit-post/src/editor.native.js:12:1)
      at Object.<anonymous> (packages/edit-post/src/index.native.js:13:1)
      at Object.<anonymous> (packages/components/src/mobile/link-settings/index.native.js:10:1)
      at Object.<anonymous> (packages/components/src/index.native.js:78:1)
      at Object.<anonymous> (packages/rich-text/src/component/index.native.js:20:1)
      at Object.<anonymous> (packages/rich-text/src/index.js:37:1)
 ---> at Object.<anonymous> (packages/block-editor/src/index.js:4:1)   
      at Object.<anonymous> (packages/block-library/src/list/edit.js:6:1)
      at Object.<anonymous> (packages/block-library/src/list/test/edit.native.js:9:1)

@gziolo Is my understanding is correct? If yes, then is there any example where this has been fixed before, or have I created a monster? 😞 Also, sorry for writing so much; I wanted to make myself clear as I thought this very confusing to explain.

@gziolo
Copy link
Member

gziolo commented Dec 2, 2020

Yes, those cyclic dependencies are bugs. That's the point of this refactoring to fix them eventually and prevent moving forward 😃

I plan to look at your PR tomorrow, great comments and awesome work 🎉

@rafaelgallani
Copy link
Contributor Author

Yes, those cyclic dependencies are bugs. That's the point of this refactoring to fix them eventually and prevent moving forward

I plan to look at your PR tomorrow, great comments and awesome work

Great, thanks! I'll keep looking at it and see if I can come up with anything else.

@gziolo gziolo added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label Dec 3, 2020
@gziolo
Copy link
Member

gziolo commented Dec 3, 2020

@hypest and @Tug, it looks like there are some architectural issues in React Native files that this PR uncovers. The packages should depend on each other in the following direction:

  • edit-post
    • block-library
      • editor
        • blocks
        • components
          • element

There is also some mix in the picture as edit-post itself might be using one of the deeper dependencies directly, and so on.

@rafaelgalani, what it means is that for now, we should live hardcoded strings outside of the @wordpress/edit-post package and fix all the issues separately. It might feel like you wasted some time, but in reality, you helped to identify potential bugs. For now, let's revert changes that create cyclic dependencies and use the revert commit as a baseline to the follow-up issue that I can create myself later.

There are other high-level packages: edit-site, edit-widgets, or edit-navigation that shouldn't be referenced externally as well. I probably should include a note in the parent issue as well.

block-directory is a snowflake here. It's an experiment that can depend on edit-post as it works as an extension to the editor so it should be fine to leave modified. I can test that once the branch is testable.

@gziolo
Copy link
Member

gziolo commented Dec 3, 2020

I missed some previous questions:

There are still some references remaining, but most of them are in the e2e-tests and e2e-tests-utils packages. What should I do in these cases? Adding edit-post as a dependency doesn't look right.

Yes, for all code related to e2e tests we should leave hard-coded strings, those are shortcuts that allow to perform more detailed assertions or set the app in a specific state.

There's also selectors.js in edit-post package, which I didn't change since it's not in a select/useSelect/withSelect/dispatch/useDispatch/withDispatch call. Should I change it anyway?

They should be left unmodified. Those are hardcoded strings used for scoping which happen to use the same names to make it easier to debug.

Should I rebase my branch or should I add one more commit on top of it?
I would prefer rebasing + force pushing to keep the commit history clean. I couldn't find recommendations for this situation in the git guidelines.

It's up to you. I personally use rebasing + force pushing, sometimes I squash commits. I think it's covered here: https://github.com/WordPress/gutenberg/blob/master/docs/contributors/git-workflow.md#keeping-your-branch-up-to-date. It's for repository members (it's you now, you can open PR directly in Gutenberg repo), there is also a section that covers forks (this branch).

@rafaelgallani rafaelgallani marked this pull request as ready for review December 4, 2020 00:33
@rafaelgallani rafaelgallani force-pushed the refactor/replace-edit-post-store-name-with-definition branch from ab78919 to e9fac2b Compare December 4, 2020 00:48
@rafaelgallani
Copy link
Contributor Author

rafaelgallani commented Dec 4, 2020

Uhm, @gziolo...

import './store';

Sorry. I haven't checked the exports... They were included in the last refactorings, so I thought that for this package they would be too, my bad. 😓
I'll add the export and check the builds to see what could be breaking again - aka want to ensure that there is really a cyclic dependency problem and not something caused by the missing exports. At least I'm getting the hang of working on the project, lol.

@rafaelgallani rafaelgallani force-pushed the refactor/replace-edit-post-store-name-with-definition branch from e9fac2b to f2a297c Compare December 4, 2020 02:21
Reverting commits that removed `"edit-post"` hardcoded store name on `"components"` and `"block-editor"` packages, due to cyclic dependencies, as referenced in WordPress#27414 (this commit will be used as baseline later).
@rafaelgallani rafaelgallani force-pushed the refactor/replace-edit-post-store-name-with-definition branch from af20ba5 to 58ab3d1 Compare December 4, 2020 20:15
@rafaelgallani
Copy link
Contributor Author

I only force-pushed to resolve the conflicts. There is no actual change to the code.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left two more comments. Once they are addressed this PR should be good to 😄

Edit: I posted this comment while doing a live stream at Twitch 😅:
https://www.twitch.tv/videos/828801176

@@ -28,6 +28,7 @@ import {
createBlock,
} from '@wordpress/blocks';
import { withDispatch, withSelect } from '@wordpress/data';
import { store as editPostStore } from '@wordpress/edit-post';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid this cyclic dependency for @wordpress/editor package and leave it as a string for now.

@@ -40,6 +40,7 @@
"@wordpress/date": "file:../date",
"@wordpress/deprecated": "file:../deprecated",
"@wordpress/dom": "file:../dom",
"@wordpress/edit-post": "file:../edit-post",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid this cyclic dependency for @wordpress/block-library package and leave it as a string for now.

@rafaelgallani
Copy link
Contributor Author

I left two more comments. Once they are addressed this PR should be good to

Edit: I posted this comment while doing a live stream at Twitch :
https://www.twitch.tv/videos/828801176

+1 follow 😆. Will fix them right away.

@hypest
Copy link
Contributor

hypest commented Dec 8, 2020

There is this issue though that codebase is tightly coupled to the specific screen - edit post. As soon as you will want to support another screens for things like a site, theme templates or maybe post comments, it will become a blocker. We don't have a solid solution for that, so far we were using props or editor settings for passing down information where necessary. It feels like we need some sort of scope detection to make it more robust. If you have some ideas, I'm happy to hear your thoughts.

👋 @gziolo, can you open a ticket to have that discussion? I feel like there must be some immediate changes we could do to adapt the native mobile blocks to use whatever is the pattern the web components have atm, but I'm not sure what that pattern is. I like how you opened #27088 with a checklist of the blocks that need refactoring and would be nice if we compile a similar one for the cases you bring up here. WDYT?

packages/block-library/package.json Outdated Show resolved Hide resolved
packages/block-library/src/button/edit.native.js Outdated Show resolved Hide resolved
packages/block-library/src/button/edit.native.js Outdated Show resolved Hide resolved
packages/block-library/src/button/edit.native.js Outdated Show resolved Hide resolved
packages/block-library/src/columns/edit.native.js Outdated Show resolved Hide resolved
packages/block-library/src/file/edit.native.js Outdated Show resolved Hide resolved
packages/block-library/src/file/edit.native.js Outdated Show resolved Hide resolved
packages/block-library/src/file/edit.native.js Outdated Show resolved Hide resolved
packages/block-library/src/latest-posts/edit.native.js Outdated Show resolved Hide resolved
packages/block-library/src/latest-posts/edit.native.js Outdated Show resolved Hide resolved
packages/editor/package.json Outdated Show resolved Hide resolved
packages/editor/src/components/provider/index.native.js Outdated Show resolved Hide resolved
packages/editor/src/components/provider/index.native.js Outdated Show resolved Hide resolved
packages/editor/src/components/provider/index.native.js Outdated Show resolved Hide resolved
@@ -13247,6 +13247,7 @@
"@wordpress/date": "file:packages/date",
"@wordpress/deprecated": "file:packages/deprecated",
"@wordpress/dom": "file:packages/dom",
"@wordpress/edit-post": "file:packages/edit-post",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@wordpress/edit-post": "file:packages/edit-post",

@gziolo
Copy link
Member

gziolo commented Dec 16, 2020

I reverted changes to @wordpress/editor and @wordpress/block-library packages. I contemplated on using export for store on @wordpress/edit-post and I think you were right, it makes sense for 3rd party plugin. @wordpress/block-directory is an internal plugin so it makes sense to keep it working this way.

I can't apply changes to the lock file using GitHub UI. Would you mind running npm install locally to regenerate the lock file? Other than that this PR should be ready to go 🎉

@gziolo
Copy link
Member

gziolo commented Dec 16, 2020

I opened #27751 to address the issue with cyclic dependencies in other packages - those reverted in this PR.

@rafaelgallani rafaelgallani force-pushed the refactor/replace-edit-post-store-name-with-definition branch from 05b7417 to 19222ce Compare December 16, 2020 21:28
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafaelgalani thank you for your great cooperation on this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Package] Edit Post /packages/edit-post [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants