From 3ccb538942187795b20f4df5a06185c8fdf8e070 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 12 Feb 2022 01:32:53 +0000 Subject: [PATCH] [Beta] Fix layout shift from previews (#4322) * [Beta] Fix layout shift from previews * Arbitrary values * Fix borked style * Remove custom styles and start again * Recreate existing layout * Try to make it work * Fix TS Co-authored-by: Dan Lebowitz --- .../components/MDX/Sandpack/CustomPreset.tsx | 29 ++-------- beta/src/components/MDX/Sandpack/Preview.tsx | 10 ++-- beta/src/components/MDX/Sandpack/index.tsx | 2 +- beta/src/styles/sandpack.css | 53 +++++++++++++++++-- beta/tailwind.config.js | 8 +-- 5 files changed, 64 insertions(+), 38 deletions(-) diff --git a/beta/src/components/MDX/Sandpack/CustomPreset.tsx b/beta/src/components/MDX/Sandpack/CustomPreset.tsx index a3ea1fe0..eae75221 100644 --- a/beta/src/components/MDX/Sandpack/CustomPreset.tsx +++ b/beta/src/components/MDX/Sandpack/CustomPreset.tsx @@ -44,13 +44,6 @@ export function CustomPreset({ } const lineCount = lineCountRef.current[activePath]; const isExpandable = lineCount > 16 || isExpanded; - const editorHeight = isExpandable ? lineCount * 24 + 24 : 'auto'; // shown lines * line height (24px) - const getHeight = () => { - if (!isExpandable) { - return editorHeight; - } - return isExpanded ? editorHeight : 406; - }; return ( <> @@ -63,31 +56,19 @@ export function CustomPreset({ ref={sandpack.lazyAnchorRef} className={cn( 'sp-layout sp-custom-layout', - showDevTools && devToolsLoaded && 'sp-layout-devtools' - )} - style={{ - // Prevent it from collapsing below the initial (non-loaded) height. - // There has to be some better way to do this... - minHeight: 216, - }}> + showDevTools && devToolsLoaded && 'sp-layout-devtools', + isExpanded && 'sp-layout-expanded' + )}> - {isExpandable && (