Skip to content

Commit 893004c

Browse files
authored
Merge pull request #1218 from aashu2006/createcapture-fallback
Add fallback preview size for DOM-only reference examples
2 parents 256581d + 2db1204 commit 893004c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/components/CodeEmbed/index.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,23 @@ export const CodeEmbed = (props) => {
4444
previewHeight = previewHeight || parseFloat(canvasMatch[2]);
4545
}
4646

47-
const largeSketch = previewWidth && previewWidth > 770 - 60;
48-
4947
// Quick hack to make room for DOM that gets added below the canvas by default
5048
const domMatch = /create(Button|Select|P|Div|Input|ColorPicker)/.exec(initialCode);
5149
if (domMatch && previewHeight) {
5250
previewHeight += 100;
5351
}
5452

53+
// Fallback preview size when no usable canvas dimensions are detected.
54+
// Ensures DOM-based examples (e.g., createCapture with noCanvas) are visible.
55+
const DEFAULT_PREVIEW_WIDTH = 400;
56+
const DEFAULT_PREVIEW_HEIGHT = 300;
57+
if (previewWidth === undefined || previewHeight === undefined) {
58+
previewWidth = previewWidth ?? DEFAULT_PREVIEW_WIDTH;
59+
previewHeight = previewHeight ?? DEFAULT_PREVIEW_HEIGHT;
60+
}
61+
62+
const largeSketch = previewWidth && previewWidth > 770 - 60;
63+
5564
const codeFrameRef = useRef(null);
5665

5766
const updateOrReRun = () => {

0 commit comments

Comments
 (0)