diff --git a/backend/docker/docker-compose-full.yml b/backend/docker/docker-compose-full.yml index 9648ebc5..027c0ac1 100644 --- a/backend/docker/docker-compose-full.yml +++ b/backend/docker/docker-compose-full.yml @@ -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: diff --git a/backend/docker/docker-compose.yml b/backend/docker/docker-compose.yml index 25ffa673..8ab031f2 100644 --- a/backend/docker/docker-compose.yml +++ b/backend/docker/docker-compose.yml @@ -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: diff --git a/frontend/package.json b/frontend/package.json index ed14d8e3..bc56b12a 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -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", diff --git a/frontend/src/hooks/useYorkieDocument.ts b/frontend/src/hooks/useYorkieDocument.ts index 8f67a6a6..c3229870 100644 --- a/frontend/src/hooks/useYorkieDocument.ts +++ b/frontend/src/hooks/useYorkieDocument.ts @@ -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"; @@ -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); } @@ -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; } @@ -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 }; }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3a08d0a9..e0a58ecc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -349,8 +349,8 @@ importers: specifier: ^1.1.0 version: 1.1.0(vite@5.4.7(@types/node@20.16.6)(terser@5.33.0)) yorkie-js-sdk: - specifier: 0.5.5 - version: 0.5.5 + specifier: 0.5.6 + version: 0.5.6 devDependencies: '@sentry/vite-plugin': specifier: ^2.20.1 @@ -7258,8 +7258,8 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} - yorkie-js-sdk@0.5.5: - resolution: {integrity: sha512-Y+3B4JGPMPSoGndZvQwf2N8w959kMcH6b2ej5H7HtzgJIUPx+qO/fMuXCeylvlh+OotIBqhawzQeueQ82+r8fw==} + yorkie-js-sdk@0.5.6: + resolution: {integrity: sha512-McWQLt8/XCUUdPxNxHBkfg5qh2Y5bAbB3mAHx05+DAEbMrYwB9n7f3xtFMbBcN2AEdPUDuk08MvD7qwG3DFx7w==} engines: {node: '>=18.0.0', npm: '>=7.1.0'} zod-to-json-schema@3.23.3: @@ -15059,7 +15059,7 @@ snapshots: yocto-queue@0.1.0: {} - yorkie-js-sdk@0.5.5: + yorkie-js-sdk@0.5.6: dependencies: '@bufbuild/protobuf': 1.10.0 '@connectrpc/connect': 1.5.0(@bufbuild/protobuf@1.10.0)