From 8c6fd0a92d303a202cdf17b85a7c0581e256d02d Mon Sep 17 00:00:00 2001 From: Rodrigo Pombo Date: Fri, 6 May 2022 11:10:59 +0000 Subject: [PATCH] Fix react 18 strict mode --- packages/mdx/next.config.js | 1 + packages/mdx/src/mini-editor/editor-shift.tsx | 12 ++++++------ packages/mdx/src/smooth-code/copy-button.tsx | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/mdx/next.config.js b/packages/mdx/next.config.js index b2774a97..3b8b2704 100644 --- a/packages/mdx/next.config.js +++ b/packages/mdx/next.config.js @@ -1,4 +1,5 @@ module.exports = { + reactStrictMode: true, redirects() { return [ { diff --git a/packages/mdx/src/mini-editor/editor-shift.tsx b/packages/mdx/src/mini-editor/editor-shift.tsx index 0b7b8c18..f09eccb2 100644 --- a/packages/mdx/src/mini-editor/editor-shift.tsx +++ b/packages/mdx/src/mini-editor/editor-shift.tsx @@ -793,21 +793,21 @@ function useSnapshots( useLayoutEffect(() => { if (!prevSnapshot) { - // debugger + const parent = ref.current! setState(s => ({ ...s, prevSnapshot: { - ...getPanelSnapshot(ref.current!, prev), - ...getTabsSnapshot(ref.current!, prev), + ...getPanelSnapshot(parent, prev), + ...getTabsSnapshot(parent, prev), }, })) } else if (!nextSnapshot) { - // debugger + const parent = ref.current! setState(s => ({ ...s, nextSnapshot: { - ...getPanelSnapshot(ref.current!, next), - ...getTabsSnapshot(ref.current!, next), + ...getPanelSnapshot(parent, next), + ...getTabsSnapshot(parent, next), }, })) } diff --git a/packages/mdx/src/smooth-code/copy-button.tsx b/packages/mdx/src/smooth-code/copy-button.tsx index 7209907c..26f82abe 100644 --- a/packages/mdx/src/smooth-code/copy-button.tsx +++ b/packages/mdx/src/smooth-code/copy-button.tsx @@ -43,7 +43,7 @@ export function CopyButton({ )}