The assistant lives beside the page, not inside it, and can change shape without its conversation restarting.

The problem

Put an AI sidebar inside the page layout and sooner or later a drawer opens and slides right over the chat.

Then you want the assistant to be tucked away, docked beside the page, or expanded to full page. The tempting build is three components, one per state. Switching remounts the chat, and an answer that was halfway through streaming starts over or vanishes.

What I concluded

A sibling, not a child

The shell has two overlay scopes side by side. The main area holds the nav, the page, and every drawer or palette that should cover the page. The assistant area sits next to it with its own scope, so nothing opened in the page can bleed into the chat.

<Shell>                   app-wide singletons (toasts, tooltips)
  <MainArea>              own portal scope, page overlays go here
    <Nav /> <Outlet /> <Drawer />
  </MainArea>
  <AssistantArea>         separate portal scope
    <AssistantPanel />
  </AssistantArea>
</Shell>

The assistant reads what’s on screen but owns no route state. When it filters or navigates, the shell turns that into a URL write, so the back button undoes it. See Navigation.

One conversation, moved

Render the conversation once into a detached host node, and move that node between slots when the panel changes shape. React never sees it leave, so nothing remounts.

const host = useMemo(() => document.createElement("div"), []);
useLayoutEffect(() => {
  const slot = mode === "page" ? pageSlot.current
                               : sideSlot.current;
  slot?.append(host); // a move, not a remount
}, [mode]);
return createPortal(<Chat layout={mode} />, host);

The demo counts mounts so you can check: switch shapes mid-answer and the count stays at 1. A DOM move does blur focus and can reset scroll, so in a real app save both before the move and restore them after.

The conversation state itself lives above the panel, in the app. The panel is just where it happens to be drawn right now.

Rules

  • The assistant is a sibling of the page. Separate overlay scopes, so drawers never cover it.
  • It reads the screen but owns no routes. Its open state isn’t part of where you are.
  • It changes the view through the URL. Back undoes it.
  • Render once, move the node. Never one component per panel shape.
  • Keep state above the panel. Shape is layout, not data.

What you get

The assistant can watch and steer the page without fighting it for space, focus or history. And you can tuck it away or expand it mid-answer without losing a word.

Related: Screen context, Event stream, Plant shop demo