Skip to content

Commit

Permalink
Update yorkie to v0.5.6 (#413)
Browse files Browse the repository at this point in the history
* Update `yorkie` to `v0.5.6`

* Add comment for cleanup codes
  • Loading branch information
devleejb authored Nov 22, 2024
1 parent a79b2cc commit e161e23
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/docker/docker-compose-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ services:
- "yorkie:yorkie"

yorkie:
image: "yorkieteam/yorkie:0.5.5"
image: "yorkieteam/yorkie:0.5.6"
command: ["server", "--enable-pprof"]
restart: always
ports:
Expand Down
2 changes: 1 addition & 1 deletion backend/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.8"

services:
yorkie:
image: "yorkieteam/yorkie:0.5.5"
image: "yorkieteam/yorkie:0.5.6"
command: ["server", "--enable-pprof"]
restart: always
ports:
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"refractor": "^4.8.1",
"validator": "^13.12.0",
"vite-plugin-package-version": "^1.1.0",
"yorkie-js-sdk": "0.5.5"
"yorkie-js-sdk": "0.5.6"
},
"devDependencies": {
"@sentry/vite-plugin": "^2.20.1",
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/hooks/useYorkieDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Color from "color";
import randomColor from "randomcolor";
import { useCallback, useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { useSearchParams } from "react-router-dom";
import { useBeforeUnload, useSearchParams } from "react-router-dom";
import * as yorkie from "yorkie-js-sdk";
import { selectAuth } from "../store/authSlice";
import { CodePairDocType } from "../store/editorSlice";
Expand Down Expand Up @@ -80,8 +80,7 @@ export const useYorkieDocument = (
if (!client || !doc) return;

try {
await client.detach(doc);
await client.deactivate();
await client.deactivate({ keepalive: true });
} catch (error) {
console.error("Error during Yorkie cleanup:", error);
}
Expand All @@ -102,8 +101,7 @@ export const useYorkieDocument = (

// Clean up if the component is unmounted before the initialization is done
if (!mounted) {
await newClient.detach(newDoc);
await newClient.deactivate();
await newClient.deactivate({ keepalive: true });
return;
}

Expand Down Expand Up @@ -131,11 +129,17 @@ export const useYorkieDocument = (
createYorkieDocument,
]);

// Clean up yorkie document on unmount
// For example, when the user navigates to a different page
useEffect(() => {
return () => {
cleanUpYorkieDocument();
};
}, [cleanUpYorkieDocument]);

// Clean up yorkie document on beforeunload
// For example, when the user closes the tab or refreshes the page
useBeforeUnload(cleanUpYorkieDocument);

return { client, doc };
};
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e161e23

Please sign in to comment.