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

fix: byo hocuspocus provider does not work #3834

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dpnova
Copy link
Collaborator

@dpnova dpnova commented Dec 6, 2024

Checklist

  • [] yarn typecheck <-- failing on unrelated changes
  • yarn lint:fix
  • yarn test
  • yarn brl
  • yarn changeset
  • ui changelog

Options allow a byo yjs provider, but it is overwritten during plugin config.

This allows us to provide our own hocuspocus provider, but wraps any relevant hooks so that it doesn't break existing plate expectations around state management.

Copy link

codesandbox bot commented Dec 6, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

changeset-bot bot commented Dec 6, 2024

🦋 Changeset detected

Latest commit: 079b13f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@udecode/plate-yjs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ❌ Failed (Inspect) Dec 6, 2024 0:28am

@dpnova dpnova changed the title fix: options allow a byo provider, but overwrite it during plugin config fix: byo hocuspocus provider does not work Dec 6, 2024
@dpnova
Copy link
Collaborator Author

dpnova commented Dec 6, 2024

Sorry I don't have perms to see what is wrong with the vercel build

@dpnova
Copy link
Collaborator Author

dpnova commented Dec 19, 2024

Including our patch used with pnpm patch here which is how we get this in our own application:

diff --git a/dist/react/index.mjs b/dist/react/index.mjs
index a4705afd2b8aecba9d47c6b5c33ddc70de635686..9ea882c4de9d8f3580a9825cdba8d78fb3a8dc09 100644
--- a/dist/react/index.mjs
+++ b/dist/react/index.mjs
@@ -87,11 +87,33 @@ var BaseYjsPlugin = createTSlatePlugin({
     provider: {}
   }
 }).extend(({ getOptions, setOption }) => {
-  const { hocuspocusProviderOptions } = getOptions();
+  const { hocuspocusProviderOptions, provider } = getOptions();
+  if(provider) {
+    provider.setConfiguration({
+        onAwarenessChange() {},
+        onConnect() {
+          setOption("isConnected", true);
+          provider.onConnect();
+        },
+        onDisconnect(data) {
+          setOption("isConnected", false);
+          setOption("isSynced", false);
+          provider.onDisconnect(data);
+        },
+        onSynced(data) {
+          setOption("isSynced", true);
+          provider.onSynced(data);
+        }
+
+    })
+    return {
+      options: { provider }
+    }
+  }
   if (!hocuspocusProviderOptions) {
     throw new Error("HocuspocusProvider configuration is required");
   }
-  const provider = new HocuspocusProvider(__spreadProps(__spreadValues({}, hocuspocusProviderOptions), {
+  const defaultProvider = new HocuspocusProvider(__spreadProps(__spreadValues({}, hocuspocusProviderOptions), {
     onAwarenessChange() {
     },
     onConnect() {
@@ -112,7 +134,7 @@ var BaseYjsPlugin = createTSlatePlugin({
     }
   }));
   return {
-    options: { provider }
+    options: { provider:defaultProvider }
   };
 });

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

Successfully merging this pull request may close these issues.

1 participant