Error: "Duplicate use of selection JSON ID gapcursor" when using @atlaskit/editor-core in Forge app

When I using @atlaskit/editor-core in Forge app, I got an error
image
In package.json:

"@atlaskit/css-reset": "^6.0.1",
    "@atlaskit/editor-core": "^184.0.0",
    "@atlaskit/link-provider": "^1.6.3",
    "@atlaskit/media-core": "^34.1.2",
    "@forge/bridge": "2.5.6",
    "adf-builder": "^3.3.0",
    "next-intl": "^2.14.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-intl-next": "npm:react-intl@^5.18.1",
    "react-scripts": "^4.0.3"
2 Likes

By any chance, are you trying to serialize Editor from @atlaskit/editor-core anywhere?

I have the same problem with Editor @atlaskit/editor-core. Do you know how to fix this problem?

I can’t quite remember what the issue was exactly. But it seems like I found something that shouldn’t have been serialized, and it was added to serialization by mistake. I removed it, and an error was gone. Sorry, my comment probably won’t be helpful at this point.

1 Like

I’m working on a Connect app and had this error while using modern versions of yarn. I was previously on yarn v1, but after looking at the warnings on this page eg:

The dependencies of editor is a complex beast and can confuse some package managers (npm does not seem to result in duplicates, but yarn does).
We have encountered many strange bugs that were caused by duplicated packages in a product codebase. It is highly recommend to deduplicate packages to work around the yarn bug.
Be sure to dedupe your packages after adding or upgrading @atlaskit/editor-core in your package.json file. Our recommendation is to use yarn-deduplicate.

I decided it might be time to investigate the newer yarn versions, since as mentioned on the yarn-deduplicate page above, yarn v2 onwards has deduplication functionality natively. So it seemed like a sensible upgrade.

However it results in this error when using even the most basic implementation of the Editor component (no serialization or anything like that). From some debugging in the browser it is happening inside code from the ‘editor-common’ package, but I could find no solutions to be implemented from the app side.

Switching back to yarn v1 this error no longer happens. I’m not performing any particular deduplication, simply doing a regular yarn install. Disappointing to find such an opposite outcome to what is indicated on the editor-core page, but who knows, YMMV.

2 Likes

I’m facing the same issue with the Connect app. Here’s the workaround I’m following:

  • Analyze the yarn.lock file: I identify exactly where duplicate versions of editor-common are caused by parent dependencies.
  • Upgrade compatible versions: I check the package.json files for each version of editor-core and editor-common (using unpkg.com) to find compatible upgrades.
  • Resolve internal dependencies (optional): Sometimes, additional internal dependency resolutions need to be added to the package.json file.

However, this approach becomes tedious during each release build process due to yarn install. It requires manual intervention to ensure compatibility every time.

That sounds very painful indeed, have you considered adding resolutions for the editor packages? @atlaskit/editor-common and @atlaskit/adf-schema commonly cause issues if there are multiple versions of the dependency.

I think you can also pull in the latest published version of the packages these days, unless you’re relying on deprecated functionality in an older version.

This exception still occurs when you bundle the newest version of the editor with vite. I happens because some extension are registered twice. The last registration wins, however the implementation throws when it happens. We’re using pnpm patch (native feature of pnpm) and comment out the line where the exception is thrown. And yes, this is a hack. However, it has been working reliably for years. Also pnpm update makes in manageable.