Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: fix editor title temporary flicker on tab switch (#9548)

01zulfid48643cbb98c
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 9ef5e4dae..b1f34dd9f 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -711,12 +711,12 @@ function EditorChrome(props: PropsWithChildren<EditorProps>) {
}
});
- const editorTitle = document.querySelector("#editor-title");
+ const editorTitle = document.querySelector(`#editor-title-${id}`);
if (editorTitle instanceof HTMLTextAreaElement) {
resizeTextarea(editorTitle);
}
}
- const observer = new ResizeObserver(debounce(onResize, 500));
+ const observer = new ResizeObserver(onResize);
observer.observe(editorScrollRef.current);
return () => {
observer.disconnect();
diff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsx
index df7d35951..d9aa85156 100644
--- a/apps/web/src/components/editor/title-box.tsx
+++ b/apps/web/src/components/editor/title-box.tsx
@@ -100,7 +100,7 @@ function TitleBox(props: TitleBoxProps) {
<Textarea
ref={inputRef}
variant="clean"
- id="editor-title"
+ id={`editor-title-${id}`}
data-test-id="editor-title"
className="editorTitle"
placeholder={strings.noteTitle()}
@@ -157,6 +157,8 @@ export default React.memo(TitleBox, (prevProps, nextProps) => {
});
export function resizeTextarea(input: HTMLTextAreaElement) {
+ if (input.scrollHeight === 0) return;
+
input.style.height = "auto";
requestAnimationFrame(() => {
input.style.height = input.scrollHeight + "px";