Repository navigation
feat(SlotLayout): make WorkspaceLayout composable and keep a slot's base mounted under layers - #3469
MartinCupela wants to merge 8 commits into
Conversation
…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.
…kspace-layout # Conflicts: # examples/vite/src/ChatLayout/Panels.tsx
👋 Hi, want a second pair of eyes on this?I'm Jeffery, Stream's review agent. I look for bugs, regressions, missing tests and slow paths, and I only post findings I've checked against the code.
Or comment |
|
Size Change: +6.53 kB (+0.58%) Total Size: 1.14 MB 📦 View Changed
ℹ️ View Unchanged
|
oliverlaz
left a comment
There was a problem hiding this comment.
Review notes, focused on regressions and breaking changes.
Apps on the built-in workspace layout and the SDK stylesheet shouldn't notice a difference. Apps that build their own layout from stream-chat-react/slot-layout hit two breaking changes, and this ships as feat, so it would go out as a minor:
- The new
display: contentswrapper around a slot's base breaks app CSS that targets a slot's direct child or uses:emptyon slots. WorkspaceLayoutnow calls every slot's renderer during its own render, so renderers that call hooks can crash when another slot opens or closes.
Either mark them as breaking (a BREAKING CHANGE: footer and an entry in ai-docs/v15-breaking-changes.md), or avoid them. Details and smaller notes are inline.
| })); | ||
| const isSlotShowingAnything = ({ shown, slot }: (typeof resolvedSlots)[number]) => | ||
| shown !== false || !!slotLayers?.[slot]?.length; | ||
| const isEmpty = !resolvedSlots.some(isSlotShowingAnything); |
There was a problem hiding this comment.
Not new in this PR, but the check is rewritten here: isEmpty counts hidden slots as showing something. A layout whose only slot with content is hidden (for example a persistent list hidden by navigation) shows a blank area instead of ChatViewEmptyPlaceholder. Consider ignoring hiddenSlots here, or confirm the blank state is intended.
There was a problem hiding this comment.
Not changed; this is intended. The placeholder replaces the slots, so treating a hidden slot as empty would unmount what it holds (a persistent list hidden by navigation) and lose its state. The JSDoc and the migration guide now say hidden slots count.
🤖 Addressed by Claude Code
WorkspaceLayout called every slot's renderer during its own render, so a renderer that called hooks broke as soon as another slot opened or closed. Each slot entry (the base and each layer) is now a component that runs its renderer, so renderers may call hooks. Slot takes a `fallback`, shown while its base renders nothing. The layout decides on the placeholder from bindings: a bound slot counts whatever its renderer returns. renderBetweenSlots gets whether each neighbour is occupied. In the vite example the member panel closes when its member can't be resolved.
…fix ThreadListSlot's fallback (#3474)
…ile covered A slot's base sat in an SDK wrapper even without layers, so app CSS on a slot's direct child stopped matching. The base is now the slot's own child again, in a stable position, so it still stays mounted while layers open and close. While a layer covers it, its top-level elements get an inline display: none, aria-hidden and inert, restored when the last layer closes; elements it adds meanwhile are hidden as they appear. The SDK's empty-slot rules are back to :empty.
…' into fix/slot-layers-workspace-layout
Closes REACT-1291
Closes REACT-1215
🎯 Goal
<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.WorkspaceLayoutwas 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):emptybehave as on master while no layer is open.display: none,aria-hiddenandinert, and get their previous values back when the last layer closes. An inline style wins over app CSS from any cascade layer, without!important. Elements the base renders while covered are hidden as they appear (MutationObserver).div.str-chat__chat-view__slot-layerwhosedisplayis set inline:contentson top,nonewhile another layer covers it.fallback(shown while the base renders nothing),styleand a forwarded ref.WorkspaceLayout(REACT-1215)content, else its binding's renderer, else a per-slotfallback. The placeholder shows only while no slot shows anything, decided from bindings without running renderers: content, a binding of a kind with a renderer, a fallback or a layer counts. Hidden slots count too, so the placeholder never unmounts a hidden list.className, a forwarded rootref,sidebar(rendered as given between the nav rail and the slots),renderBetweenSlots(previousSlot, nextSlot, { isPreviousSlotOccupied, isNextSlotOccupied }), and per slotclassName,styleandelementRef. All additive.ChannelSlot/ThreadSlotdraw no layers themselves; wrapping them in<Slot>gives layers. Documented and tested.Vite example
ChatLayout/Views/) renderWorkspaceLayout. Every slot's base and layers go throughchatViewSlotRenderers(ChatLayout/Panels/).useSecondarySlotTopand the stalelayer: truecomment are removed.CustomChannelListItemis removed: the SDK row plus the example'sderiveWorkspaceNavigationgive the same plain-click and ⌘-click behaviour, and the row now announces channel switches.userProfilebinding 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.ChatLayout/{Views,Panels,MemberDetail,hooks,Resize,UrlSync},ChannelList/,ChannelDetail/,Sidebar/SidebarContext.tsx, andAccessibilityNavigation/skipNavigationTargets.ts.REACT-1293 (merged in from #3474): the built-in layout renders
ChatView'schildren, andThreadListSlot'sfallbackshows only until the list is bound.Docs:
ai-docs/ai-migration-v14-v15.mdgets a "Composing a layout withWorkspaceLayout" section, a note that layers come from<Slot>, and a CSS note on how a covered base is hidden and where layers render.Behaviour changes worth noting:
Slotsetsstyle.display,aria-hiddenandinerton the base's top-level elements. A base that changes those itself while covered can undo the hiding; a base that renders bare text at its top level can't be hidden.null/false; now that slot is empty and hidden, and itsfallback(SlotFallback) shows if one is set.SlotandWorkspaceLayoutareforwardRefcomponents. JSX is unaffected, butParameters<typeof Slot>[0]/Parameters<typeof WorkspaceLayout>[0]stop compiling: useSlotProps/WorkspaceLayoutProps.Checks
yarn lint,yarn typesand the vite example'stsc; after the merge the 185 SlotLayout tests, lint and types pass. New tests:Slot.test.tsx(11) andWorkspaceLayout.test.tsx(19).🎨 UI Changes
No intended visual change. Checked in the vite example (Chrome):