@yorkie-js/react 0.6.1-rc5 → 0.6.1-rc7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,9 +11,9 @@ import { PropsWithChildren } from 'react';
11
11
  */
12
12
  export declare const DocumentProvider: <R, P extends Indexable = Indexable>({ docKey, initialRoot, initialPresence, children, }: {
13
13
  docKey: string;
14
- initialRoot: R;
15
- initialPresence: P;
16
- children: React.ReactNode;
14
+ initialRoot?: R | undefined;
15
+ initialPresence?: P | undefined;
16
+ children?: React.ReactNode;
17
17
  }) => JSX.Element;
18
18
 
19
19
  export { JSONArray }
@@ -20338,6 +20338,14 @@ class Client {
20338
20338
  }
20339
20339
  return this.enqueueTask(task);
20340
20340
  }
20341
+ /**
20342
+ * `hasDocument` checks if the given document is attached to this client.
20343
+ * @param docKey - the key of the document.
20344
+ * @returns true if the document is attached to this client.
20345
+ */
20346
+ hasDocument(docKey) {
20347
+ return this.attachmentMap.has(docKey);
20348
+ }
20341
20349
  /**
20342
20350
  * `attach` attaches the given document to this client. It tells the server that
20343
20351
  * this client will synchronize the given document.
@@ -21084,7 +21092,9 @@ const YorkieProvider = ({ apiKey, rpcAddr = "https://api.yorkie.dev", children }
21084
21092
  }
21085
21093
  activateClient();
21086
21094
  return () => {
21087
- client == null ? void 0 : client.deactivate({ keepalive: true });
21095
+ if (client && client.isActive()) {
21096
+ client.deactivate({ keepalive: true });
21097
+ }
21088
21098
  };
21089
21099
  }, [apiKey, rpcAddr]);
21090
21100
  return /* @__PURE__ */ jsx(YorkieContext.Provider, { value: { client, loading, error }, children });
@@ -21150,7 +21160,9 @@ const DocumentProvider = ({
21150
21160
  }
21151
21161
  attachDocument();
21152
21162
  return () => {
21153
- client.detach(newDoc);
21163
+ if (client && client.hasDocument(docKey)) {
21164
+ client.detach(newDoc);
21165
+ }
21154
21166
  };
21155
21167
  }, [client, clientLoading, clientError, docKey]);
21156
21168
  const update = useCallback(