Skip to content

feat(SlotLayout): make WorkspaceLayout composable and keep a slot's base mounted under layers - #3469

Open
MartinCupela wants to merge 2 commits into
masterfrom
fix/slot-layers-workspace-layout
Open

MartinCupela wants to merge 2 commits into
masterfrom
fix/slot-layers-workspace-layout

Conversation

@MartinCupela

@MartinCupela MartinCupela commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes REACT-1291
Closes REACT-1215

🎯 Goal

  • REACT-1291: <Slot> remounted its base content when the first layer opened and when the last one closed, so a thread or channel under a member profile lost its scroll position and local state.
  • REACT-1215: WorkspaceLayout was too rigid for a real app, so the vite example hand-built its layout and its secondary-slot overlays. That meant the SDK layout path (placeholder, layers, registry rendering) wasn't exercised by our own app.

🛠 Implementation details

Slot (REACT-1291)

  • The base renders in the same keyed wrapper (div.str-chat__chat-view__slot-layer) with or without layers, so pushing the first layer and popping the last keep it mounted.
  • Each entry's display is set inline: contents while on top, none while covered, plus hidden/aria-hidden. App CSS from a later cascade layer can't show a covered entry.
  • The base wrapper renders only while the base has content, so an unbound slot stays :empty.
  • The SDK's own empty and divider rules use :not(:has(> :not(:empty))), so a slot whose child renders nothing is still hidden.
  • New: style and a forwarded ref.

WorkspaceLayout (REACT-1215)

  • Each slot shows its content, else its binding's renderer, else a per-slot fallback. The placeholder shows only while no slot shows anything; layers count.
  • New optional props: className, a forwarded root ref, sidebar (rendered as given between the nav rail and the slots), renderBetweenSlots(previousSlot, nextSlot), and per slot className, style and elementRef. All additive.
  • ChannelSlot/ThreadSlot draw no layers themselves; wrapping them in <Slot> gives layers. Documented and tested.

Vite example

  • The channels and threads views (ChatLayout/Views/) render WorkspaceLayout. Every slot's base and layers go through chatViewSlotRenderers (ChatLayout/Panels/).
  • The hand-rolled overlays, useSecondarySlotTop and the stale layer: true comment are removed.
  • CustomChannelListItem is removed: the SDK row plus the example's deriveWorkspaceNavigation give the same plain-click and ⌘-click behaviour, and the row now announces channel switches.
  • A ⌘/ctrl-click on a message author's avatar or a mention opens that member's profile in the secondary slot only when the message is in the main channel (or its replies). From any other channel it opens the member modal instead, because the slot's userProfile binding carries only the user id and is resolved against the main channel. The channel header's avatar is unaffected: a ⌘/ctrl-click on it still opens the channel's details in the secondary slot.
  • Avatars and mentions in the second channel's message list (a channel opened beside the main one) now open the member modal on a plain click and on a ⌘/ctrl-click. They opened nothing before, on master too, because that list had no member-click handlers.
  • Example code is reorganised: ChatLayout/{Views,Panels,MemberDetail,hooks,Resize,UrlSync}, ChannelList/, ChannelDetail/, Sidebar/SidebarContext.tsx, and AccessibilityNavigation/skipNavigationTargets.ts.

Docs: ai-docs/ai-migration-v14-v15.md gets a "Composing a layout with WorkspaceLayout" section, a note that layers come from <Slot>, and a CSS note on the display: contents wrapper (use descendant selectors and the SDK's empty-slot selector).

Behaviour changes worth noting:

  • The base of a slot is now always inside a display: contents wrapper, so integrator selectors on a slot's direct child (.str-chat__chat-view__slot > .x) stop matching.
  • An element passed as <Slot> children keeps the slot from being :empty even if it renders nothing; the SDK still hides that slot.
  • A WorkspaceLayout rendered by the app runs the slot renderers during its own render. Renderers must not call hooks; this is documented on ChatViewSlotRenderers.

Checks

  • 4584 tests pass, plus yarn lint, yarn types and the vite example's tsc. New tests: Slot.test.tsx (7) and WorkspaceLayout.test.tsx (16).
  • Bundle: +295 B min+gzip across the changed modules, +4 B CSS.

🎨 UI Changes

No intended visual change. Checked in the vite example (Chrome):

  • placeholders;
  • a thread beside the channel;
  • a channel layer over the thread, then back: same DOM node;
  • a second channel scrolled up with channel details layered over it: same node and scroll position after closing;
  • the member profile in a modal (plain click) and in the slot (⌘-click);
  • a member's avatar in the second channel's list opens the modal on a plain click and on a ⌘-click;
  • sidebar collapse and resize, and secondary panel resize;
  • the 1100px and 375px layouts;
  • two threads side by side;
  • the "Also sent in channel → View" reveal;
  • the SDK channel row with a plain click and a ⌘-click.

…ase mounted under layers

Slot renders its base in the same keyed wrapper with or without layers, so
opening the first layer and closing the last no longer remount it. Covered
entries are hidden with an inline display, so app CSS cannot show them.

WorkspaceLayout resolves each slot (content, binding, fallback) and shows the
placeholder only while no slot shows anything. New optional props: className,
a forwarded ref, sidebar, renderBetweenSlots, and per-slot className, style and
elementRef. Slot gains style and a forwarded ref.

The vite example's channels and threads views now render WorkspaceLayout with
slotRenderers instead of a hand-built layout and overlays, use the SDK channel
row, and are split into Views, Panels and feature folders.
…list

Avatars and mentions in the channel opened beside the main one opened nothing.
The list now gets the same member-detail click handlers as the main channel's.
A plain click and a ⌘/ctrl-click both open the member modal, because the slot
profile resolves members of the main channel only.

This branch was successfully deployed

2 active deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant