Open History to see the last commit
1import { useLayoutEffect, useRef } from "react";
2
3/**
4 * Where the Notes app currently sits on screen. The app itself is rendered
5 * once (into `host`, through a portal) and the active layout's slot adopts
6 * the host element, so crossing a breakpoint moves the app's DOM instead of
7 * recreating its React tree.
8 */
9export function AppSlot({ host }: { host: HTMLElement }) {
10 const slotRef = useRef<HTMLDivElement>(null);
11
12 useLayoutEffect(() => {
13 const slot = slotRef.current;
14 if (!slot) return;
15 slot.append(host);
16 return () => {
17 if (host.parentElement === slot) host.remove();
18 };
19 }, [host]);
20
21 return <div ref={slotRef} className="h-full" />;
22}