Skip to content

Commit e385f39

Browse files
author
Rajat
committed
Scroll height fix
1 parent bab46b6 commit e385f39

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

packages/page-blocks/src/blocks/embed/widget.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Section } from "@courselit/page-primitives";
77
import { SandboxedEmbed } from "../../components";
88

99
export default function Widget({
10-
id,
1110
settings: {
1211
contentType,
1312
content,
@@ -30,8 +29,10 @@ export default function Widget({
3029

3130
const formattedHeight = `${height}px`;
3231

33-
// Check if content is "script" or "iframe" (not a direct URL)
34-
const isEmbedCode = contentType === "script";
32+
// Check if content is "script" type but only contains an iframe (no actual scripts)
33+
const hasScript = contentType === "script" && /<script[\s>]/i.test(content);
34+
const isPureIframe =
35+
contentType === "script" && !hasScript && /<iframe[\s>]/i.test(content);
3536

3637
const containerStyle =
3738
aspectRatio && aspectRatio !== "default"
@@ -40,7 +41,7 @@ export default function Widget({
4041
width: "100%",
4142
paddingTop: `calc(100% / (${aspectRatio.split(":")[0]} / ${aspectRatio.split(":")[1]}))`,
4243
} as React.CSSProperties)
43-
: isEmbedCode
44+
: hasScript
4445
? ({} as React.CSSProperties)
4546
: ({ height: formattedHeight } as React.CSSProperties);
4647

@@ -53,21 +54,29 @@ export default function Widget({
5354
width: "100%",
5455
height: "100%",
5556
} as React.CSSProperties)
56-
: isEmbedCode
57+
: hasScript
5758
? ({} as React.CSSProperties)
5859
: ({ height: "100%" } as React.CSSProperties);
5960

6061
const renderContent = () => {
61-
if (isEmbedCode) {
62-
// Content is a script or iframe code - use sandboxed embed for dynamic height
62+
if (hasScript) {
63+
// Content has actual script tags - use sandboxed embed
6364
return (
6465
<SandboxedEmbed
65-
id={id}
6666
content={content}
6767
className="w-full"
6868
style={iframeStyle}
6969
/>
7070
);
71+
} else if (isPureIframe) {
72+
// Content is a pure iframe without scripts - render directly
73+
return (
74+
<div
75+
className="w-full"
76+
style={iframeStyle}
77+
dangerouslySetInnerHTML={{ __html: content }}
78+
/>
79+
);
7180
} else {
7281
// URL-based content
7382
return (

packages/page-blocks/src/components/sandboxed-embed.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export const SandboxedEmbed = ({
3838
<html>
3939
<head>
4040
<style>
41-
html, body { margin: 0; padding: 0; height: auto; min-height: 100%; }
42-
#content-wrapper { overflow: auto; height: auto; }
41+
html, body { margin: 0; padding: 0; overflow: hidden; }
42+
#content-wrapper { overflow: hidden; height: auto; }
4343
</style>
4444
</head>
4545
<body>
@@ -91,6 +91,7 @@ export const SandboxedEmbed = ({
9191
width: "100%",
9292
height: height,
9393
border: "none",
94+
overflow: "hidden",
9495
...style,
9596
}}
9697
sandbox="allow-scripts allow-popups allow-forms allow-same-origin"

0 commit comments

Comments
 (0)