mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2026-08-08 02:02:33 +00:00
Onboarding: re-fit container-width thumbnails on resize
This commit is contained in:
@@ -41,10 +41,6 @@ function ExampleThumbnail({ spec }: { spec: Record<string, unknown> }) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const node = hostRef.current;
|
const node = hostRef.current;
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
// TODO: thumbnails render once at mount width and don't call handle.resize(),
|
|
||||||
// so a `width: 'container'` chart won't re-fit when the window resizes and the
|
|
||||||
// grid reflows the card. Cosmetic only (the card clips/letterboxes via overflow
|
|
||||||
// hidden) on a brief first-run surface; wire a resize observer if it ever shows.
|
|
||||||
let handle: RenderHandle | null = null;
|
let handle: RenderHandle | null = null;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
// `container` width fits the card; a fixed height keeps every card uniform.
|
// `container` width fits the card; a fixed height keeps every card uniform.
|
||||||
@@ -60,8 +56,18 @@ function ExampleThumbnail({ spec }: { spec: Record<string, unknown> }) {
|
|||||||
// somehow fails to render must never break onboarding — leave the card
|
// somehow fails to render must never break onboarding — leave the card
|
||||||
// image blank and let the name + description carry it.
|
// image blank and let the name + description carry it.
|
||||||
});
|
});
|
||||||
|
// A `container`-width chart only re-reads its size on a window resize, so the
|
||||||
|
// grid reflowing a card (window resize → new column width) needs the same
|
||||||
|
// synthesized re-fit LivePreview uses. The observer reads `handle` lazily, so
|
||||||
|
// it no-ops until the async render resolves.
|
||||||
|
let ro: ResizeObserver | undefined;
|
||||||
|
if (typeof ResizeObserver !== 'undefined') {
|
||||||
|
ro = new ResizeObserver(() => handle?.resize());
|
||||||
|
ro.observe(node);
|
||||||
|
}
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
ro?.disconnect();
|
||||||
handle?.destroy();
|
handle?.destroy();
|
||||||
};
|
};
|
||||||
}, [spec, uiTheme]);
|
}, [spec, uiTheme]);
|
||||||
|
|||||||
Reference in New Issue
Block a user