From b865f1248c546d7db9dad07bd9586e4822870803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 27 Sep 2022 15:35:58 +0200 Subject: [PATCH 1/7] Don't crash when building docs --- src/drafts/MarkdownEditor/_FormattingTools.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/drafts/MarkdownEditor/_FormattingTools.tsx b/src/drafts/MarkdownEditor/_FormattingTools.tsx index 4341276c625..a7ce20b08a6 100644 --- a/src/drafts/MarkdownEditor/_FormattingTools.tsx +++ b/src/drafts/MarkdownEditor/_FormattingTools.tsx @@ -1,5 +1,4 @@ import React, {forwardRef, useImperativeHandle, useRef, useEffect} from 'react' -import '@github/markdown-toolbar-element' export type FormattingTools = { header: () => void @@ -51,6 +50,8 @@ export const FormattingTools = forwardRef reference: () => referenceRef.current?.click() })) + require('@github/markdown-toolbar-element') + return ( From 25ec829cab3e1c8072ae4e310b14c0b8e13c46c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 27 Sep 2022 15:44:47 +0200 Subject: [PATCH 2/7] Remove import again after bad merge --- src/drafts/MarkdownEditor/_FormattingTools.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/drafts/MarkdownEditor/_FormattingTools.tsx b/src/drafts/MarkdownEditor/_FormattingTools.tsx index 97d26af25d6..1bdc8de21bd 100644 --- a/src/drafts/MarkdownEditor/_FormattingTools.tsx +++ b/src/drafts/MarkdownEditor/_FormattingTools.tsx @@ -1,5 +1,4 @@ import React, {forwardRef, useImperativeHandle, useRef} from 'react' -import '@github/markdown-toolbar-element' export type FormattingTools = { header: () => void From 42470391dc87fc3587db07f2d80a32b4ddf5db8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 27 Sep 2022 23:04:18 +0200 Subject: [PATCH 3/7] Replace require call with a dynamic import --- src/drafts/MarkdownEditor/_FormattingTools.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/drafts/MarkdownEditor/_FormattingTools.tsx b/src/drafts/MarkdownEditor/_FormattingTools.tsx index 1bdc8de21bd..0c171f3dfb8 100644 --- a/src/drafts/MarkdownEditor/_FormattingTools.tsx +++ b/src/drafts/MarkdownEditor/_FormattingTools.tsx @@ -1,4 +1,4 @@ -import React, {forwardRef, useImperativeHandle, useRef} from 'react' +import React, {forwardRef, useImperativeHandle, useRef, useEffect} from 'react' export type FormattingTools = { header: () => void @@ -48,7 +48,11 @@ export const FormattingTools = forwardRef reference: () => referenceRef.current?.click() })) - require('@github/markdown-toolbar-element') + useEffect(() => { + ;(async function () { + await import('@github/markdown-toolbar-element') + })() + }) return ( From 2c41f8ba6e842ed80e94e852b2c8ce60ec648773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 27 Sep 2022 23:21:39 +0200 Subject: [PATCH 4/7] Disable prettier rule --- src/drafts/MarkdownEditor/_FormattingTools.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/drafts/MarkdownEditor/_FormattingTools.tsx b/src/drafts/MarkdownEditor/_FormattingTools.tsx index 0c171f3dfb8..40bdd5f470e 100644 --- a/src/drafts/MarkdownEditor/_FormattingTools.tsx +++ b/src/drafts/MarkdownEditor/_FormattingTools.tsx @@ -49,7 +49,8 @@ export const FormattingTools = forwardRef })) useEffect(() => { - ;(async function () { + // eslint-disable-next-line prettier/prettier + (async function () { await import('@github/markdown-toolbar-element') })() }) From 97947fac02c4839dac6534c9edcab1fd3f27d8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Wed, 28 Sep 2022 16:45:35 +0200 Subject: [PATCH 5/7] Revert "Replace require call with a dynamic import" This reverts commit 42470391dc87fc3587db07f2d80a32b4ddf5db8e. See https://github.com/nodejs/node/issues/35889 --- src/drafts/MarkdownEditor/_FormattingTools.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/drafts/MarkdownEditor/_FormattingTools.tsx b/src/drafts/MarkdownEditor/_FormattingTools.tsx index 40bdd5f470e..1bdc8de21bd 100644 --- a/src/drafts/MarkdownEditor/_FormattingTools.tsx +++ b/src/drafts/MarkdownEditor/_FormattingTools.tsx @@ -1,4 +1,4 @@ -import React, {forwardRef, useImperativeHandle, useRef, useEffect} from 'react' +import React, {forwardRef, useImperativeHandle, useRef} from 'react' export type FormattingTools = { header: () => void @@ -48,12 +48,7 @@ export const FormattingTools = forwardRef reference: () => referenceRef.current?.click() })) - useEffect(() => { - // eslint-disable-next-line prettier/prettier - (async function () { - await import('@github/markdown-toolbar-element') - })() - }) + require('@github/markdown-toolbar-element') return ( From 3c7083588ca971abefcf5d265dd1eec04d324b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Fri, 30 Sep 2022 16:19:27 +0200 Subject: [PATCH 6/7] Wrap `@github/markdown-toolbar-element` require in `useEffect` Co-authored-by: Josh Black --- src/drafts/MarkdownEditor/_FormattingTools.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/drafts/MarkdownEditor/_FormattingTools.tsx b/src/drafts/MarkdownEditor/_FormattingTools.tsx index 1bdc8de21bd..15ee0ab7fdf 100644 --- a/src/drafts/MarkdownEditor/_FormattingTools.tsx +++ b/src/drafts/MarkdownEditor/_FormattingTools.tsx @@ -1,4 +1,4 @@ -import React, {forwardRef, useImperativeHandle, useRef} from 'react' +import React, {forwardRef, useImperativeHandle, useRef, useEffect} from 'react' export type FormattingTools = { header: () => void @@ -48,7 +48,9 @@ export const FormattingTools = forwardRef reference: () => referenceRef.current?.click() })) - require('@github/markdown-toolbar-element') + useEffect(() => { + require('@github/markdown-toolbar-element') + }) return ( From 2db90618042631d19422b057f5dc4e7cedf59240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Wed, 5 Oct 2022 09:50:51 +0200 Subject: [PATCH 7/7] Don't evaluate on every render Co-authored-by: Matthew Costabile --- src/drafts/MarkdownEditor/_FormattingTools.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drafts/MarkdownEditor/_FormattingTools.tsx b/src/drafts/MarkdownEditor/_FormattingTools.tsx index 15ee0ab7fdf..4d610565d78 100644 --- a/src/drafts/MarkdownEditor/_FormattingTools.tsx +++ b/src/drafts/MarkdownEditor/_FormattingTools.tsx @@ -50,7 +50,7 @@ export const FormattingTools = forwardRef useEffect(() => { require('@github/markdown-toolbar-element') - }) + }, []) return (