Skip to content

Commit

Permalink
fix(protocol-designer,app): use dynamic import for react-scan to avoi…
Browse files Browse the repository at this point in the history
…d build issue (#17087)

* fix(protocol-designer,app): use dynamic import for react-scan to avoid build issue
  • Loading branch information
koji authored Dec 11, 2024
1 parent b32aa12 commit 96fc13e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
18 changes: 12 additions & 6 deletions app/src/App/DesktopApp.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { scan } from 'react-scan'
import { useState, Fragment } from 'react'
import { Navigate, Route, Routes, useMatch } from 'react-router-dom'
import { ErrorBoundary } from 'react-error-boundary'
Expand Down Expand Up @@ -52,11 +51,18 @@ export const DesktopApp = (): JSX.Element => {

// note for react-scan
const enableReactScan = useFeatureFlag('reactScan')
if (typeof window !== 'undefined') {
scan({
enabled: enableReactScan,
log: true,
})
// Dynamically import `react-scan` to avoid build errors
if (typeof window !== 'undefined' && enableReactScan) {
import('react-scan')
.then(({ scan }) => {
scan({
enabled: enableReactScan,
log: true,
})
})
.catch(error => {
console.error('Failed to load react-scan:', error)
})
}

const desktopRoutes: RouteProps[] = [
Expand Down
18 changes: 12 additions & 6 deletions protocol-designer/src/ProtocolEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { scan } from 'react-scan'
import { DndProvider } from 'react-dnd'
import { HashRouter } from 'react-router-dom'
import { HTML5Backend } from 'react-dnd-html5-backend'
Expand All @@ -16,11 +15,18 @@ import { getEnableReactScan } from './feature-flags/selectors'
export function ProtocolEditor(): JSX.Element {
// note for react-scan
const enableReactScan = useSelector(getEnableReactScan)
if (typeof window !== 'undefined') {
scan({
enabled: enableReactScan,
log: true,
})
// Dynamically import `react-scan` to avoid build errors
if (typeof window !== 'undefined' && enableReactScan) {
import('react-scan')
.then(({ scan }) => {
scan({
enabled: enableReactScan,
log: true,
})
})
.catch(error => {
console.error('Failed to load react-scan:', error)
})
}

return (
Expand Down

0 comments on commit 96fc13e

Please sign in to comment.