Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(docsite): close the template preview on teardown, and cap its header height (#6075)

Ernest9bc4a62fd327
diff --git a/apps/docsite/src/components/TemplatePreviewDialog.tsx b/apps/docsite/src/components/TemplatePreviewDialog.tsx
index 7f08d47831..cfa26da4d3 100644
--- a/apps/docsite/src/components/TemplatePreviewDialog.tsx
+++ b/apps/docsite/src/components/TemplatePreviewDialog.tsx
@@ -26,6 +26,7 @@ import {
useCallback,
useEffect,
useDeferredValue,
+ useRef,
useState,
useTransition,
} from 'react';
@@ -106,6 +107,21 @@ const styles = stylex.create({
width: '100%',
minWidth: 0,
},
+ // The CLI command shrinks before the buttons do, and stays on one line.
+ commandGroup: {
+ flexShrink: 1,
+ minWidth: 0,
+ },
+ commandCode: {
+ flexShrink: 1,
+ minWidth: 0,
+ whiteSpace: 'nowrap',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ },
+ noShrink: {
+ flexShrink: 0,
+ },
skeletonOverlay: {
position: 'absolute',
insetInline: '16px',
@@ -159,7 +175,7 @@ function TemplatePreviewHeader({
}>
<Heading level={2}>{item.name}</Heading>
{item.description && (
- <Text type="body" color="secondary">
+ <Text type="body" color="secondary" maxLines={2}>
{item.description}
</Text>
)}
@@ -167,8 +183,11 @@ function TemplatePreviewHeader({
);
const copyButton = (
- <HStack gap={2} vAlign="center">
- <Code>{`npx @astryxdesign/cli template ${item.slug}`}</Code>
+ <HStack gap={2} vAlign="center" xstyle={styles.commandGroup}>
+ <Code
+ xstyle={
+ styles.commandCode
+ }>{`npx @astryxdesign/cli template ${item.slug}`}</Code>
<Button
variant="ghost"
isIconOnly
@@ -176,6 +195,7 @@ function TemplatePreviewHeader({
label={cmdCopied ? 'Copied!' : 'Copy install command'}
icon={<Icon icon={cmdCopied ? 'check' : 'copy'} color="inherit" />}
onClick={onCopyCommand}
+ xstyle={styles.noShrink}
/>
</HStack>
);
@@ -193,6 +213,7 @@ function TemplatePreviewHeader({
category: item.category,
});
}}
+ xstyle={styles.noShrink}
/>
);
@@ -244,6 +265,30 @@ export function TemplatePreviewDialog({
const [cmdCopied, setCmdCopied] = useState(false);
const [isPending, startTransition] = useTransition();
+ // Release the top layer when this dialog is torn down while still open.
+ //
+ // `showModal()` makes the rest of the document inert, and `close()` is the
+ // only thing that undoes it — removing the element does not. Dialog closes on
+ // an `isOpen` transition, which never happens here: "Open in Playground" is a
+ // client-side navigation, so React tears this subtree down with the dialog
+ // still open and the playground arrives with an invisible modal holding the
+ // whole page inert, unclickable until a reload.
+ //
+ // The element is captured on mount rather than read during cleanup, because
+ // by cleanup time this tree is on its way out and `closest()` may no longer
+ // reach it. Teardown, not unmount: React destroys effects when a subtree is
+ // hidden too, which is what a router does to the outgoing route — and that is
+ // the path that was breaking.
+ const hostRef = useRef<HTMLDivElement>(null);
+ useEffect(() => {
+ const dialog = hostRef.current?.closest('dialog');
+ return () => {
+ if (dialog?.open) {
+ dialog.close();
+ }
+ };
+ }, []);
+
const count = items.length;
const current = items[index];
// The deferred index drives the heavy preview surface — it lags behind
@@ -334,7 +379,7 @@ export function TemplatePreviewDialog({
}
content={
<LayoutContent isScrollable={false} padding={0}>
- <div {...stylex.props(styles.body)}>
+ <div {...stylex.props(styles.body)} ref={hostRef}>
<TemplatePreviewSurface
key={deferredCurrent.slug}
slug={deferredCurrent.slug}