From 12786dd2c2c77b3cd9de1e27e0ab2f0ea082ffee Mon Sep 17 00:00:00 2001 From: Danilo Woznica Date: Fri, 3 Dec 2021 16:11:09 +0000 Subject: [PATCH 1/6] fix: lint warning --- .eslintrc | 4 +- sandpack-client/src/client.ts | 2 + .../src/components/CodeEditor/CodeMirror.tsx | 3 + .../src/components/CodeEditor/utils.ts | 1 + .../CodeViewer/CodeViewer.stories.tsx | 2 +- .../src/components/Navigator/index.tsx | 1 + .../src/components/Preview/index.tsx | 14 +++-- .../src/components/TranspiledCode/index.tsx | 14 ++++- .../src/contexts/sandpackContext.tsx | 8 ++- .../src/hooks/useCodeSandboxLink.ts | 1 + sandpack-react/src/hooks/useErrorMessage.ts | 1 + .../src/hooks/useLoadingOverlayState.ts | 1 + .../src/presets/CustomSandpack.stories.tsx | 3 +- .../src/templates/Templates.stories.tsx | 3 +- sandpack-react/src/themes/Theme.stories.tsx | 3 +- .../Hero/HeroDesktop/HeroDesktop.tsx | 2 + .../components/Intro/Sections/Custom.tsx | 1 + .../components/Intro/Sections/Editor.tsx | 5 +- .../components/Intro/Sections/Layout.tsx | 8 ++- .../components/Intro/Sections/Template.tsx | 1 + .../components/Intro/Sections/Theme.tsx | 3 +- .../landing/components/common/Clipboard.tsx | 61 +++++++++---------- 22 files changed, 89 insertions(+), 53 deletions(-) diff --git a/.eslintrc b/.eslintrc index a0532af30..5c5387ff7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -43,7 +43,7 @@ // Consistently sort props "react/jsx-sort-props": [ - "warn", + "error", { "ignoreCase": true, // key, ref must always come first @@ -57,7 +57,7 @@ // Group module and relative imports "import/order": [ - "warn", + "error", { // Imports are grouped as follows: "groups": [ diff --git a/sandpack-client/src/client.ts b/sandpack-client/src/client.ts index 62c108178..db0660876 100644 --- a/sandpack-client/src/client.ts +++ b/sandpack-client/src/client.ts @@ -167,9 +167,11 @@ export class SandpackClient { "file-resolver", async (data: { m: "isFile" | "readFile"; p: string }) => { if (data.m === "isFile") { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return this.options.fileResolver!.isFile(data.p); } + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return this.options.fileResolver!.readFile(data.p); }, this.iframe.contentWindow diff --git a/sandpack-react/src/components/CodeEditor/CodeMirror.tsx b/sandpack-react/src/components/CodeEditor/CodeMirror.tsx index dc32535cd..a16ca90a7 100644 --- a/sandpack-react/src/components/CodeEditor/CodeMirror.tsx +++ b/sandpack-react/src/components/CodeEditor/CodeMirror.tsx @@ -249,6 +249,7 @@ export const CodeMirror = React.forwardRef( }; // TODO: Would be nice to reconfigure the editor when these change, instead of recreating with all the extensions from scratch + // eslint-disable-next-line react-hooks/exhaustive-deps }, [initEditor, showLineNumbers, wrapContent, themeId, decorators]); React.useEffect(() => { @@ -261,6 +262,7 @@ export const CodeMirror = React.forwardRef( ) { cmView.current.contentDOM.focus(); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); // Update editor when code passed as prop from outside sandpack changes @@ -271,6 +273,7 @@ export const CodeMirror = React.forwardRef( changes: { from: 0, to: view.state.doc.length, insert: code }, }); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [code]); React.useEffect( diff --git a/sandpack-react/src/components/CodeEditor/utils.ts b/sandpack-react/src/components/CodeEditor/utils.ts index 8f925a7de..46738d57d 100644 --- a/sandpack-react/src/components/CodeEditor/utils.ts +++ b/sandpack-react/src/components/CodeEditor/utils.ts @@ -172,5 +172,6 @@ export const useCombinedRefs = ( // eslint-disable-next-line @typescript-eslint/no-explicit-any (ref as any).current = element; }), + // eslint-disable-next-line react-hooks/exhaustive-deps refs ); diff --git a/sandpack-react/src/components/CodeViewer/CodeViewer.stories.tsx b/sandpack-react/src/components/CodeViewer/CodeViewer.stories.tsx index 6c28e610d..2501f40d7 100644 --- a/sandpack-react/src/components/CodeViewer/CodeViewer.stories.tsx +++ b/sandpack-react/src/components/CodeViewer/CodeViewer.stories.tsx @@ -1,5 +1,5 @@ import type { Story } from "@storybook/react"; -import React, { useCallback, useEffect, useRef, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import { SandpackProvider } from "../../contexts/sandpackContext"; import { SandpackThemeProvider } from "../../contexts/themeContext"; diff --git a/sandpack-react/src/components/Navigator/index.tsx b/sandpack-react/src/components/Navigator/index.tsx index 0ff9f2a6d..400a97e8a 100644 --- a/sandpack-react/src/components/Navigator/index.tsx +++ b/sandpack-react/src/components/Navigator/index.tsx @@ -45,6 +45,7 @@ export const Navigator: React.FC = ({ }, clientId); return () => unsub(); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const handleInputChange = (e: React.ChangeEvent) => { diff --git a/sandpack-react/src/components/Preview/index.tsx b/sandpack-react/src/components/Preview/index.tsx index f4369de86..d39e78eda 100644 --- a/sandpack-react/src/components/Preview/index.tsx +++ b/sandpack-react/src/components/Preview/index.tsx @@ -71,19 +71,23 @@ export const SandpackPreview: React.FC = ({ loadingScreenRegisteredRef.current = true; React.useEffect(() => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const iframeElement = iframeRef.current!; - registerBundler(iframeElement, clientId.current); + const clientIdValue = clientId.current; - const unsub = listen((message) => { + registerBundler(iframeElement, clientIdValue); + + const unsubscribe = listen((message) => { if (message.type === "resize") { setComputedAutoHeight(message.height); } - }, clientId.current); + }, clientIdValue); return () => { - unsub(); - unregisterBundler(clientId.current); + unsubscribe(); + unregisterBundler(clientIdValue); }; + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const handleNewURL = (newUrl: string) => { diff --git a/sandpack-react/src/components/TranspiledCode/index.tsx b/sandpack-react/src/components/TranspiledCode/index.tsx index 260dbb801..11ad9d4cd 100644 --- a/sandpack-react/src/components/TranspiledCode/index.tsx +++ b/sandpack-react/src/components/TranspiledCode/index.tsx @@ -18,11 +18,15 @@ export const SandpackTranspiledCode: React.FC = (props) => { const hiddenIframeRef = React.useRef(null); React.useEffect(() => { - const hiddenIframe = hiddenIframeRef.current!; - sandpack.registerBundler(hiddenIframe, "hidden"); + const hiddenIframe = hiddenIframeRef.current; + + if (hiddenIframe) { + sandpack.registerBundler(hiddenIframe, "hidden"); + } return () => { sandpack.unregisterBundler("hidden"); }; + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ( @@ -34,7 +38,11 @@ export const SandpackTranspiledCode: React.FC = (props) => { {...props} /> )} -