Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
use React.memo instead useMemo to improve the semantics
Oleg Isonen9e44588b3595
diff --git a/app/canvas/features/wrapper-component/text-editor/editor.tsx b/app/canvas/features/wrapper-component/text-editor/editor.tsxindex d664756aef..307ac56461 100644--- a/app/canvas/features/wrapper-component/text-editor/editor.tsx+++ b/app/canvas/features/wrapper-component/text-editor/editor.tsx@@ -3,6 +3,7 @@ import { RichTextPlugin, HistoryPlugin } from "./lexical";import { InstancePlugin } from "./plugins/plugin-instance";import { ToolbarConnectorPlugin } from "./plugins/plugin-toolbar-connector";import { OnChangePlugin } from "./plugins/plugin-on-change";+import { memo } from "react";type EditorProps = {children?: JSX.Element;@@ -28,3 +29,6 @@ export const Editor = ({</>);};++// Prevent rerender because in editing mode Editor controls the node.+export const EditorMemoized = memo(Editor, () => true);diff --git a/app/canvas/features/wrapper-component/text-editor/index.ts b/app/canvas/features/wrapper-component/text-editor/index.tsindex 22bd56ccca..f0eb9d8838 100644--- a/app/canvas/features/wrapper-component/text-editor/index.ts+++ b/app/canvas/features/wrapper-component/text-editor/index.ts@@ -2,4 +2,4 @@ export { LexicalComposer } from "./lexical";export { config } from "./config";export { useContentEditable } from "./hooks/use-content-editable";export { useIsEditing } from "./hooks/use-is-editing";-export { Editor } from "./editor";+export { EditorMemoized } from "./editor";diff --git a/app/canvas/features/wrapper-component/wrapper-component.tsx b/app/canvas/features/wrapper-component/wrapper-component.tsxindex 62b2c76294..ad18489284 100644--- a/app/canvas/features/wrapper-component/wrapper-component.tsx+++ b/app/canvas/features/wrapper-component/wrapper-component.tsx@@ -12,7 +12,11 @@ import { useBreakpoints } from "~/shared/nano-states";import { useCss } from "./use-css";import { useDraggable } from "./use-draggable";import { useEnsureFocus } from "./use-ensure-focus";-import { Editor, useContentEditable, useIsEditing } from "./text-editor";+import {+ EditorMemoized,+ useContentEditable,+ useIsEditing,+} from "./text-editor";import noop from "lodash.noop";type WrapperComponentDevProps = {@@ -85,11 +89,9 @@ export const WrapperComponentDev = ({},};- // Prevent rerender because in editing mode Editor controls the node.- const editor = useMemo(() => {- if (isEditing === false) return;+ if (isEditing) {return (- <Editor+ <EditorMemoizedinstance={instance}editable={<Component {...props} />}onChange={(updates) => {@@ -97,11 +99,6 @@ export const WrapperComponentDev = ({}}/>);- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [isEditing]);-- if (editor) {- return editor;}return (