Skip to content

Commit

Permalink
fix: avoid ssr memory leak with global shallow ref
Browse files Browse the repository at this point in the history
  • Loading branch information
logotip4ik committed Oct 26, 2024
1 parent e668cbb commit 48d7f03
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions composables/tiptap/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Transaction } from '@tiptap/pm/state';

import { Editor } from '@tiptap/core';
import type { ShallowRef } from 'vue';

import { Editor } from '@tiptap/core';
import Blockquote from '@tiptap/extension-blockquote';
import Bold from '@tiptap/extension-bold';
import BulletList from '@tiptap/extension-bullet-list';
Expand All @@ -20,13 +21,16 @@ import Placeholder from '@tiptap/extension-placeholder';
import Strike from '@tiptap/extension-strike';
import TaskItem from '@tiptap/extension-task-item';
import TaskList from '@tiptap/extension-task-list';

import Text from '@tiptap/extension-text';

import proxy from 'unenv/runtime/mock/proxy';
import { BubbleMenu } from './extensions/bubble-menu';
import { EmojiPicker } from './extensions/emoji-picker';
import { Link } from './extensions/link';

const isTyping = /* #__PURE__ */ ref(false);
const currentTiptap: ShallowRef<Editor | undefined> = import.meta.server ? proxy : shallowRef<Editor>();
const isTyping = /* #__PURE__ */ ref(false); // this will be removed in server bundle

const debouncedClearTyping = debounce(() => isTyping.value = false, 500);

Expand Down Expand Up @@ -93,7 +97,6 @@ function initTiptap() {
});
}

const currentTiptap = shallowRef<Editor>();
export function useTiptap() {
const editor = initTiptap()!;

Expand Down

0 comments on commit 48d7f03

Please sign in to comment.