diff --git a/.changeset/breezy-nights-repair.md b/.changeset/breezy-nights-repair.md new file mode 100644 index 0000000000..1f4aa422c3 --- /dev/null +++ b/.changeset/breezy-nights-repair.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Fix webframe height issue diff --git a/packages/gitbook/e2e/internal.spec.ts b/packages/gitbook/e2e/internal.spec.ts index 1109963382..34088e136b 100644 --- a/packages/gitbook/e2e/internal.spec.ts +++ b/packages/gitbook/e2e/internal.spec.ts @@ -779,7 +779,10 @@ const testCases: TestsCase[] = [ url: 'blocks/integrations', run: async (page) => { await waitForCookiesDialog(page); - const mermaidIframe = page.locator('iframe[title*="mermaid"]').contentFrame(); + const mermaidIframe = page + .locator('iframe[title*="mermaid"]') + .first() + .contentFrame(); await expect(mermaidIframe.getByText('Mermaid', { exact: true })).toBeVisible(); await expect(mermaidIframe.getByText('Diagram', { exact: true })).toBeVisible(); }, diff --git a/packages/react-contentkit/src/ElementWebframe.tsx b/packages/react-contentkit/src/ElementWebframe.tsx index 8dfedbfa06..e0474087a6 100644 --- a/packages/react-contentkit/src/ElementWebframe.tsx +++ b/packages/react-contentkit/src/ElementWebframe.tsx @@ -2,13 +2,14 @@ import type { ContentKitWebFrame } from '@gitbook/api'; import React from 'react'; -import { useResizeObserver } from 'usehooks-ts'; import { Icon } from '@gitbook/icons'; import { useContentKitClientContext } from './context'; import { resolveDynamicBinding } from './dynamic'; import type { ContentKitClientElementProps } from './types'; +const MIN_HEIGHT = 32; // minimum height for the iframe in pixels + export function ElementWebframe(props: ContentKitClientElementProps) { const { element } = props; @@ -159,21 +160,22 @@ export function ElementWebframe(props: ContentKitClientElementProps (size.height ?? 0) - ? Math.min(Math.round(liveWidth / aspectRatio), size.height ?? 32) - : 'auto'; + const aspectRatio = + size.aspectRatio || + element.aspectRatio || + (iframeRef.current?.clientWidth && height + ? iframeRef.current.clientWidth / height + : undefined); if (!mounted) { return ; } + // only use height measurement if no aspect ratio is defined + const useHeightMeasurement = !aspectRatio && height; + return (