Skip to content

Commit ee5d8ca

Browse files
authored
fix(suspensive.org/Sandpack): exclude custom props from 'SandpackPreview' spread to prevent DOM warnings (#1953)
# Overview - Destructure custom props (`layout`, `showConsole`, `showConsoleButton`) from `previewOptions` before spreading to `SandpackPreview` - These props are not part of `PreviewProps` but were passed to the DOM via `{...props.previewOptions}`, causing React warnings: - `showConsoleButton` prop on a DOM element - `showConsole` prop on a DOM element ## Screenshot ### AS-IS <img width="1725" height="939" alt="image" src="https://github.com/user-attachments/assets/154ac894-6583-4936-886f-e339f3a05b9e" /> <img width="1727" height="943" alt="image" src="https://github.com/user-attachments/assets/5ca2a958-d762-4691-bcc0-aeed366edc48" /> <img width="1728" height="942" alt="image" src="https://github.com/user-attachments/assets/58cb5088-ca16-4124-83d7-00ae5601ef5c" /> ### TO-BE <img width="1724" height="939" alt="image" src="https://github.com/user-attachments/assets/a4cb8d82-2727-408f-8a40-f2f485354adf" /> ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
1 parent a9603df commit ee5d8ca

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

docs/suspensive.org/src/components/Sandpack/CustomPreset.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@ export const CustomPreset = (
2525
'layoutOptions' | 'editorOptions' | 'previewOptions'
2626
>
2727
) => {
28+
const {
29+
layout,
30+
showConsole: showConsoleProp,
31+
showConsoleButton: showConsoleButtonProp,
32+
...restPreviewOptions
33+
} = props.previewOptions ?? {}
34+
const mode = layout ?? 'preview'
35+
const showConsole = showConsoleProp ?? false
36+
const showConsoleButton = showConsoleButtonProp ?? false
37+
2838
const dragEventTargetRef = useRef<(EventTarget & HTMLDivElement) | null>(null)
2939

3040
const [horizontalSize, setHorizontalSize] = useState(50)
3141
const [verticalSize, setVerticalSize] = useState(60)
32-
const [consoleVisibility, setConsoleVisibility] = useState(
33-
props.previewOptions?.showConsole ?? false
34-
)
42+
const [consoleVisibility, setConsoleVisibility] = useState(showConsole)
3543
const [counter, setCounter] = useState(0)
3644

37-
const mode = props.previewOptions?.layout ?? 'preview'
38-
const showConsole = props.previewOptions?.showConsole ?? false
39-
const showConsoleButton = props.previewOptions?.showConsoleButton ?? false
40-
4145
const hasRightColumn = showConsole || showConsoleButton
4246
const RightColumn = hasRightColumn ? SandpackStack : Fragment
4347

@@ -152,7 +156,7 @@ export const CustomPreset = (
152156
showSandpackErrorOverlay={false}
153157
actionsChildren={actionsChildren}
154158
style={topRowStyle}
155-
{...props.previewOptions}
159+
{...restPreviewOptions}
156160
>
157161
<ErrorOverlay />
158162
</SandpackPreview>

0 commit comments

Comments
 (0)