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

Cannot unlock an object that was not locked before #228

Closed
kylefordui opened this issue Jun 14, 2023 · 12 comments
Closed

Cannot unlock an object that was not locked before #228

kylefordui opened this issue Jun 14, 2023 · 12 comments

Comments

@kylefordui
Copy link

kylefordui commented Jun 14, 2023

I am attempting to use this in a React environment, without WordPress but am getting the following error, not sure why. I have included an image of the error with the code being used. Any help would be greatly appreciated, thank you. I am running in a React environment with Vite.

block-editor-error isolated-block-editor-code
@johngodley
Copy link
Member

I don't know what locking does and it may not be supported here. Have you looked at the Gutenberg code?

https://github.com/WordPress/gutenberg/blob/4d0f303bf0bf231db12221f03548cbc067c302b1/packages/private-apis/src/implementation.js#L182

@kylefordui
Copy link
Author

Wow thanks for the quick reply!
Yes I have had a look at that, I am not 100% sure what locking does either. I have just implemented the block editor as per the example above and am getting this error. Seems to be running the IsolatedBlock editor through an unlock function. Would you expect any errors from my example above? Not sure if / how I could exclude this unlock function as I don't think it will be needed.

@johngodley
Copy link
Member

I would suggest supplying more props and some settings to the editor, as per the examples. You have probably triggered some error condition

@tobiasegli
Copy link

@kylefordui, I got the same error when I installed the @wordpress/data package at v9.5.0. It was gone once I installed the package at the version 9.1.0.

@welsipieters
Copy link

I can't seem to get rid of this. Weirdly enough, only the Vite build system seems to trigger this issue for me. Running the code OP provided in a CRA app will allow it to run successfully.

@AntonioJABV
Copy link

AntonioJABV commented Jul 12, 2023

Same happening on our side.
Brand new Vite project, basic block editor, and just the same error in the console.

function App() {
  return (
    <IsolatedBlockEditor>
      <EditorLoaded onLoaded={() => {}} onLoading={() => {}} />
      <DocumentSection>Extra Information</DocumentSection>

      <ToolbarSlot>
        <button>Beep!</button>
      </ToolbarSlot>
    </IsolatedBlockEditor>
  );
}

Output V2.25.0:

14:13:06.559 implementation.js:182 Uncaught Error: Cannot unlock an object that was not locked before. 
    at unlock3 (implementation.js:182:9)
    at index.js:30:1
unlock3 @ implementation.js:182
(anonymous) @ index.js:30

Output V2.23.1:

14:23:45.209 chunk-C6RUTG3L.js?v=775dde92:sourcemap:18255 Uncaught Error: Cannot unlock an object that was not locked before. 
    at unlock3 (chunk-C6RUTG3L.js?v=775dde92:sourcemap:18255:11)
    at node_modules/@wordpress/blocks/build-module/store/index.js (chunk-C6RUTG3L.js?v=775dde92:sourcemap:18327:5)
    at __init (chunk-CEIBQOFC.js?v=775dde92:sourcemap:16:56)
    at node_modules/@wordpress/blocks/build-module/index.js (chunk-C6RUTG3L.js?v=775dde92:sourcemap:26140:5)
    at __init (chunk-CEIBQOFC.js?v=775dde92:sourcemap:16:56)
    at node_modules/@wordpress/editor/build-module/hooks/custom-sources-backwards-compatibility.js (chunk-C6RUTG3L.js?v=775dde92:sourcemap:267695:5)
    at __init (chunk-CEIBQOFC.js?v=775dde92:sourcemap:16:56)
    at node_modules/@wordpress/editor/build-module/hooks/index.js (chunk-C6RUTG3L.js?v=775dde92:sourcemap:374619:5)
    at __init (chunk-CEIBQOFC.js?v=775dde92:sourcemap:16:56)
    at node_modules/@wordpress/editor/build-module/index.js (chunk-C6RUTG3L.js?v=775dde92:sourcemap:374774:5)
unlock3 @ chunk-C6RUTG3L.js?v=775dde92:sourcemap:18255
node_modules/@wordpress/blocks/build-module/store/index.js @ chunk-C6RUTG3L.js?v=775dde92:sourcemap:18327
__init @ chunk-CEIBQOFC.js?v=775dde92:sourcemap:16
node_modules/@wordpress/blocks/build-module/index.js @ chunk-C6RUTG3L.js?v=775dde92:sourcemap:26140
__init @ chunk-CEIBQOFC.js?v=775dde92:sourcemap:16
node_modules/@wordpress/editor/build-module/hooks/custom-sources-backwards-compatibility.js @ chunk-C6RUTG3L.js?v=775dde92:sourcemap:267695
__init @ chunk-CEIBQOFC.js?v=775dde92:sourcemap:16
node_modules/@wordpress/editor/build-module/hooks/index.js @ chunk-C6RUTG3L.js?v=775dde92:sourcemap:374619
__init @ chunk-CEIBQOFC.js?v=775dde92:sourcemap:16
node_modules/@wordpress/editor/build-module/index.js @ chunk-C6RUTG3L.js?v=775dde92:sourcemap:374774
__init @ chunk-CEIBQOFC.js?v=775dde92:sourcemap:16
node_modules/@automattic/isolated-block-editor/build/index.js @ @automattic_isolated-block-editor_build.js?v=775dde92:sourcemap:8561
__require2 @ chunk-CEIBQOFC.js?v=775dde92:sourcemap:19
(anonymous) @ @automattic_isolated-block-editor_build.js?v=775dde92:sourcemap:8635

If some required props are missing as specified in this message #228 (comment), would you mind @johngodley sharing which ones are the minimum parameters required for making a working editor?

I've been searching them but I cannot manage to get the list of minimum required parameters. I've been two days fighting with this issue, without solution yet. All help is pleased 🙏

Best regards,
Antonio,

@johngodley
Copy link
Member

I suspect you were using different versions of the @wordpress packages than is supported by this repo. 2.26.0 has updated the packages and that may solve some of these issues.

@AntonioJABV
Copy link

Perfect. On my side it has been fixed automatically when I upgraded to version ^2.26.0 😉

@stevep
Copy link

stevep commented Jul 27, 2023

For anyone else still running into this, I had to make sure I was loading the version of wp-private-apis that WordPress supply's rather than bundlilng my own from node_modules, because I was also relying on the version of wp-block-editor that WordPress supply's.

@welsipieters
Copy link

@stevep How do you mean? I just upgraded to ^2.26.0, but am still running into this issue. After some sleuthing, I saw that @wordpress/private-apis is in my yarn.lock twice. Once @^0.19.0, @^0.20.0. Could this be whats caussing my issue?

@welsipieters
Copy link

welsipieters commented Aug 2, 2023

I managed to identify a cause and temporary solution. Initially, I installed isolated-block-editor@^2.26.0 in an isolated environment and it worked as expected. After conducting an in-depth comparison of yarn lockfiles, I surmised that the problem was version-related.

As a workaround, I used Yarn's resolutions feature to fix the versions of the @wordpress/* packages required by @automattic/isolated-block-editor. (This was done by transferring these dependencies from the project's package.json file into the resolutions array in my own package.json file.)

For me, this is just a stopgap measure, and I am still in search of a more permanent solution addressing the underlying issue. I hope this insight assists with troubleshooting and resolution of this issue.

@johngodley
Copy link
Member

Gutenberg's modules are sometimes incompatible with different versions of other modules, and there's no easy way to handle this. The versions listed in the project package.json are known to be working versions (a snapshot from a particular version of Gutenberg), but anything outside of that may or may not work. Gutenberg moves at a much faster speed than this project can keep up with, so it's not possible to ensure that everything is always going to work with newer versions of Gutenberg.

I'm going to close this issue as it looks to be 'solved'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants