From 5e6a4939d15690f05bc8b5aee03c37a964d998c8 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Sun, 12 Dec 2021 21:44:44 +0000 Subject: [PATCH] Removes faulty error boundary from core, removes faulty ID provider from tldraw --- apps/electron/package.json | 8 +- .../core/src/components/Canvas/Canvas.tsx | 44 +++-- .../ErrorBoundary/ErrorBoundary.tsx | 155 ------------------ .../src/components/ErrorBoundary/index.ts | 1 - .../ErrorFallback/ErrorFallback.test.tsx | 9 - .../ErrorFallback/ErrorFallback.tsx | 20 --- .../src/components/ErrorFallback/index.ts | 1 - packages/tldraw/CHANGELOG.md | 4 + packages/tldraw/src/Tldraw.tsx | 29 ++-- 9 files changed, 41 insertions(+), 230 deletions(-) delete mode 100644 packages/core/src/components/ErrorBoundary/ErrorBoundary.tsx delete mode 100644 packages/core/src/components/ErrorBoundary/index.ts delete mode 100644 packages/core/src/components/ErrorFallback/ErrorFallback.test.tsx delete mode 100644 packages/core/src/components/ErrorFallback/ErrorFallback.tsx delete mode 100644 packages/core/src/components/ErrorFallback/index.ts diff --git a/apps/electron/package.json b/apps/electron/package.json index f6df96cc3..220e73359 100644 --- a/apps/electron/package.json +++ b/apps/electron/package.json @@ -11,10 +11,10 @@ "esbuild" ], "scripts": { - "start:electron": "yarn dev", - "build:apps": "yarn build", "dev": "electron-esbuild dev", - "build": "electron-esbuild build", + "start:electron": "yarn dev", + "build:apps": "yarn build:electron", + "build:electron": "electron-esbuild build", "package": "electron-builder" }, "devDependencies": { @@ -76,4 +76,4 @@ "publish": null }, "gitHead": "a7dac0f83ad998e205c2aab58182cb4ba4e099a6" -} +} \ No newline at end of file diff --git a/packages/core/src/components/Canvas/Canvas.tsx b/packages/core/src/components/Canvas/Canvas.tsx index 27c26797d..fb88fa190 100644 --- a/packages/core/src/components/Canvas/Canvas.tsx +++ b/packages/core/src/components/Canvas/Canvas.tsx @@ -10,8 +10,6 @@ import { useKeyEvents, } from '~hooks' import type { TLBinding, TLBounds, TLPage, TLPageState, TLShape, TLSnapLine, TLUsers } from '~types' -import { ErrorFallback } from '~components/ErrorFallback' -import { ErrorBoundary } from '~components/ErrorBoundary' import { Brush } from '~components/Brush' import { Page } from '~components/Page' import { Users } from '~components/Users' @@ -93,28 +91,26 @@ export const Canvas = observer(function _Canvas< return (
- - {!hideGrid && grid && } -
- - {users && userId && ( - - )} - {pageState.brush && } - {users && } -
-
+ {!hideGrid && grid && } +
+ + {users && userId && ( + + )} + {pageState.brush && } + {users && } +
{snapLines && } diff --git a/packages/core/src/components/ErrorBoundary/ErrorBoundary.tsx b/packages/core/src/components/ErrorBoundary/ErrorBoundary.tsx deleted file mode 100644 index 5079dde8e..000000000 --- a/packages/core/src/components/ErrorBoundary/ErrorBoundary.tsx +++ /dev/null @@ -1,155 +0,0 @@ -import * as React from 'react' - -// Copied from https://github.com/bvaughn/react-error-boundary/blob/master/src/index.tsx -// (There's an issue with esm builds of this library, so we can't use it directly.) -const changedArray = (a: Array = [], b: Array = []) => - a.length !== b.length || a.some((item, index) => !Object.is(item, b[index])) - -interface FallbackProps { - error: Error - resetErrorBoundary: (...args: Array) => void -} - -interface ErrorBoundaryPropsWithComponent { - onResetKeysChange?: ( - prevResetKeys: Array | undefined, - resetKeys: Array | undefined - ) => void - onReset?: (...args: Array) => void - onError?: (error: Error, info: { componentStack: string }) => void - resetKeys?: Array - fallback?: never - FallbackComponent: React.ComponentType - fallbackRender?: never -} - -declare function FallbackRender( - props: FallbackProps -): React.ReactElement | null - -interface ErrorBoundaryPropsWithRender { - onResetKeysChange?: ( - prevResetKeys: Array | undefined, - resetKeys: Array | undefined - ) => void - onReset?: (...args: Array) => void - onError?: (error: Error, info: { componentStack: string }) => void - resetKeys?: Array - fallback?: never - FallbackComponent?: never - fallbackRender: typeof FallbackRender -} - -interface ErrorBoundaryPropsWithFallback { - onResetKeysChange?: ( - prevResetKeys: Array | undefined, - resetKeys: Array | undefined - ) => void - onReset?: (...args: Array) => void - onError?: (error: Error, info: { componentStack: string }) => void - resetKeys?: Array - fallback: React.ReactElement< - unknown, - string | React.FunctionComponent | typeof React.Component - > | null - FallbackComponent?: never - fallbackRender?: never -} - -type ErrorBoundaryProps = - | ErrorBoundaryPropsWithFallback - | ErrorBoundaryPropsWithComponent - | ErrorBoundaryPropsWithRender - -type ErrorBoundaryState = { error: Error | null } - -const initialState: ErrorBoundaryState = { error: null } - -class ErrorBoundary extends React.Component< - React.PropsWithRef>, - ErrorBoundaryState -> { - static getDerivedStateFromError(error: Error) { - return { error } - } - - state = initialState - updatedWithError = false - resetErrorBoundary = (...args: Array) => { - this.props.onReset?.(...args) - this.reset() - } - - reset() { - this.updatedWithError = false - this.setState(initialState) - } - - componentDidCatch(error: Error, info: React.ErrorInfo) { - this.props.onError?.(error, info) - } - - componentDidMount() { - const { error } = this.state - - if (error !== null) { - this.updatedWithError = true - } - } - - componentDidUpdate(prevProps: ErrorBoundaryProps) { - const { error } = this.state - const { resetKeys } = this.props - - // There's an edge case where if the thing that triggered the error - // happens to *also* be in the resetKeys array, we'd end up resetting - // the error boundary immediately. This would likely trigger a second - // error to be thrown. - // So we make sure that we don't check the resetKeys on the first call - // of cDU after the error is set - if (error !== null && !this.updatedWithError) { - this.updatedWithError = true - return - } - - if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) { - this.props.onResetKeysChange?.(prevProps.resetKeys, resetKeys) - this.reset() - } - } - - render() { - const { error } = this.state - - const { fallbackRender, FallbackComponent, fallback } = this.props - - if (error !== null) { - const props = { - error, - resetErrorBoundary: this.resetErrorBoundary, - } - if (React.isValidElement(fallback)) { - return fallback - } else if (typeof fallbackRender === 'function') { - return fallbackRender(props) - } else if (FallbackComponent) { - return - } else { - throw new Error( - 'react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop' - ) - } - } - - return this.props.children - } -} - -export { ErrorBoundary } -export type { - FallbackProps, - ErrorBoundaryPropsWithComponent, - ErrorBoundaryPropsWithRender, - ErrorBoundaryPropsWithFallback, - ErrorBoundaryProps, -} diff --git a/packages/core/src/components/ErrorBoundary/index.ts b/packages/core/src/components/ErrorBoundary/index.ts deleted file mode 100644 index 2bca71da1..000000000 --- a/packages/core/src/components/ErrorBoundary/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './ErrorBoundary' diff --git a/packages/core/src/components/ErrorFallback/ErrorFallback.test.tsx b/packages/core/src/components/ErrorFallback/ErrorFallback.test.tsx deleted file mode 100644 index 90c6b65b5..000000000 --- a/packages/core/src/components/ErrorFallback/ErrorFallback.test.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import * as React from 'react' -import { renderWithContext } from '~test' -import { ErrorFallback } from './ErrorFallback' - -describe('error fallback', () => { - test('mounts component without crashing', () => { - renderWithContext( void null} />) - }) -}) diff --git a/packages/core/src/components/ErrorFallback/ErrorFallback.tsx b/packages/core/src/components/ErrorFallback/ErrorFallback.tsx deleted file mode 100644 index 118da90f3..000000000 --- a/packages/core/src/components/ErrorFallback/ErrorFallback.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import * as React from 'react' -import { useTLContext } from '~hooks' - -interface ErrorFallbackProps { - error: Error - resetErrorBoundary: () => void -} - -export const ErrorFallback = React.memo(function ErrorFallback({ - error, - resetErrorBoundary, -}: ErrorFallbackProps) { - const { callbacks } = useTLContext() - - React.useEffect(() => { - callbacks.onError?.(error) - }, [error, resetErrorBoundary, callbacks]) - - return null -}) diff --git a/packages/core/src/components/ErrorFallback/index.ts b/packages/core/src/components/ErrorFallback/index.ts deleted file mode 100644 index 4211f3752..000000000 --- a/packages/core/src/components/ErrorFallback/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './ErrorFallback' diff --git a/packages/tldraw/CHANGELOG.md b/packages/tldraw/CHANGELOG.md index bd30f1964..5a5fe4209 100644 --- a/packages/tldraw/CHANGELOG.md +++ b/packages/tldraw/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.2.7 + +- Fixes crash due to a missing ID provider. + ## 1.2.6 - No minify on bundle. diff --git a/packages/tldraw/src/Tldraw.tsx b/packages/tldraw/src/Tldraw.tsx index 2ec592949..bc4141671 100644 --- a/packages/tldraw/src/Tldraw.tsx +++ b/packages/tldraw/src/Tldraw.tsx @@ -1,5 +1,4 @@ import * as React from 'react' -import { IdProvider } from '@radix-ui/react-id' import { Renderer } from '@tldraw/core' import { styled, dark } from '~styles' import { TDDocument, TDShape, TDBinding, TDStatus, TDUser } from '~types' @@ -301,21 +300,19 @@ export function Tldraw({ // Use the `key` to ensure that new selector hooks are made when the id changes return ( - - - + ) }