Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(home): keep the two-column layout while the rail loads (#21787)

YuTengjinge3818bdc0012
diff --git a/src/features/Home/__tests__/portraitVisibility.test.tsx b/src/features/Home/__tests__/portraitVisibility.test.tsx
index 3b18e573e78..c26a087364a 100644
--- a/src/features/Home/__tests__/portraitVisibility.test.tsx
+++ b/src/features/Home/__tests__/portraitVisibility.test.tsx
@@ -1,11 +1,13 @@
-import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';
-import type { ReactNode } from 'react';
+import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';
+import type { ComponentType, ReactNode } from 'react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { PortalViewType } from '@/store/chat/slices/portal/initialState';
interface RenderHomeOptions {
hiddenWidgets?: string[];
+ /** Module factory for the rail inbox. */
+ homeInbox?: () => { default: ComponentType<any> };
isLogin?: boolean;
portalViewType?: PortalViewType;
promo?: ReactNode;
@@ -41,6 +43,7 @@ function translate() {
const renderHome = async ({
hiddenWidgets = [],
+ homeInbox = () => stub('home-inbox'),
isLogin = true,
portalViewType,
promo,
@@ -60,7 +63,7 @@ const renderHome = async ({
vi.doMock('@/business/client/features/useHomePromoLine', () => ({
useHomePromoLine: vi.fn(() => promo),
}));
- vi.doMock('@/features/HomeInbox', () => stub('home-inbox'));
+ vi.doMock('@/features/HomeInbox', homeInbox);
function selectFromChatStore(selector: (state: unknown) => unknown) {
return selector({ portalViewType });
}
@@ -211,6 +214,35 @@ describe('Home portrait visibility', () => {
}, 20000);
});
+describe('Home rail layout', () => {
+ it('paints the rail inbox in the first commit, without a suspended empty frame', async () => {
+ await renderHome();
+
+ expect(screen.getByTestId('home-rail')).toContainElement(screen.getByTestId('home-inbox'));
+ expect(screen.getByTestId('home-main')).toHaveAttribute('data-rail-collapsed', 'false');
+ }, 20000);
+
+ it('hands the rail space to the main column only once the inbox reports it empty', async () => {
+ let reportEmpty: ((empty: boolean) => void) | undefined;
+ await renderHome({
+ homeInbox: () => ({
+ default: ({ onRailEmptyChange }: { onRailEmptyChange?: (empty: boolean) => void }) => {
+ reportEmpty = onRailEmptyChange;
+ return <div data-testid={'home-inbox'} />;
+ },
+ }),
+ });
+
+ expect(screen.getByTestId('home-main')).toHaveAttribute('data-rail-collapsed', 'false');
+
+ act(() => reportEmpty?.(true));
+ expect(screen.getByTestId('home-main')).toHaveAttribute('data-rail-collapsed', 'true');
+
+ act(() => reportEmpty?.(false));
+ expect(screen.getByTestId('home-main')).toHaveAttribute('data-rail-collapsed', 'false');
+ }, 20000);
+});
+
describe('Home input banner queue', () => {
it('reveals the next available segment after dismissing the current one', async () => {
vi.resetModules();
diff --git a/src/features/Home/index.tsx b/src/features/Home/index.tsx
index b9fdfa533ea..363067f2dfe 100644
--- a/src/features/Home/index.tsx
+++ b/src/features/Home/index.tsx
@@ -5,9 +5,14 @@ import { lazy, memo, Suspense, useCallback, useEffect, useState } from 'react';
import { useHomeUsageWidgetActive } from '@/business/client/features/HomeUsageWidget';
import { useHomePromoLine } from '@/business/client/features/useHomePromoLine';
-// Deep import, not the feature barrel: the inbox renderer loads lazily with
-// HomeInbox, and Home must not pull it into its own chunk for one provider.
+// Deep import, not the feature barrel: Home only needs the provider here.
import { EntityLinkHostProvider } from '@/features/EntityLink/host';
+/**
+ * Static on purpose: HomeModeContent already imports the inbox statically, so a
+ * `lazy` wrapper saved no bytes and only suspended the rail for one frame on
+ * every refresh, painting it empty before the cards arrived (LOBE-15206).
+ */
+import HomeInbox from '@/features/HomeInbox';
import { useChatStore } from '@/store/chat';
import { chatPortalSelectors } from '@/store/chat/selectors';
import { useGlobalStore } from '@/store/global';
@@ -62,9 +67,6 @@ const clearOnboardingHomeModeParam = () => {
// actually opened.
const TopicChatDrawer = lazy(() => import('@/features/AgentTasks/AgentTaskDetail/TopicChatDrawer'));
const AcceptancePortalDrawer = lazy(() => import('./AcceptancePortalDrawer'));
-// The inbox renders markdown, briefs and an editor; keeping it lazy leaves the
-// greeting and the input box as the only static content of the home route.
-const HomeInbox = lazy(() => import('@/features/HomeInbox'));
/** Trailing gutter that keeps the rail's cards off the page's scroll lane. */
const RAIL_GUTTER = 14;
@@ -139,11 +141,9 @@ const styles = createStaticStyles(({ css }) => ({
`,
// Collapsed, the content takes part of the vacated rail track and re-centers
// on what is left, so the page reads wider without going full-bleed.
- // An enabled rail can render no cards; reclaim its space without changing preferences.
contentCollapsed: css`
@media (width > 1100px) {
- &[data-rail-collapsed='true'],
- div:has(> #home-rail:empty) > & {
+ &[data-rail-collapsed='true'] {
transform: translateX(${COLLAPSED_CONTENT_OFFSET}px);
width: calc(100% + ${COLLAPSED_CONTENT_GAIN}px);
@@ -175,8 +175,7 @@ const styles = createStaticStyles(({ css }) => ({
`,
heroCollapsed: css`
@media (width > 1100px) {
- &[data-rail-collapsed='true'],
- div:has(> #home-rail:empty) > & {
+ &[data-rail-collapsed='true'] {
transform: translateX(${COLLAPSED_CONTENT_OFFSET}px);
&:dir(rtl) {
@@ -219,8 +218,7 @@ const styles = createStaticStyles(({ css }) => ({
transform: translateX(-${COLLAPSED_CONTENT_OFFSET * 2}px);
}
- &[data-collapsed='true'],
- div:has(> #home-rail:empty) > div > & {
+ &[data-collapsed='true'] {
transform: none;
}
}
@@ -362,6 +360,15 @@ const Home = memo(() => {
if (acceptancePortalOpen && !acceptanceDrawerMounted) setAcceptanceDrawerMounted(true);
const railVisible = resolveRailVisibility({ hiddenWidgets, isLogin, showHomeRail, usageActive });
const railCollapsed = !railVisible;
+ /**
+ * An enabled rail can settle with no cards; the main column then reclaims its
+ * space without changing the preference. Only the loaded inbox may report it:
+ * judging by an empty DOM node also matched while the lazy inbox was
+ * suspended and while its feeds were still loading, so every refresh painted one column first and
+ * slid back once the cards arrived (LOBE-15206).
+ */
+ const [railEmpty, setRailEmpty] = useState(false);
+ const contentCollapsed = railCollapsed || (isLogin && railEmpty);
const portraitVisible = Boolean(isLogin && showHomePortrait);
useEffect(() => {
@@ -403,13 +410,13 @@ const Home = memo(() => {
<Flexbox className={styles.grid}>
<div
className={cx(styles.hero, portraitVisible && styles.heroWithSpeech, styles.heroCollapsed)}
- data-rail-collapsed={railCollapsed}
+ data-rail-collapsed={contentCollapsed}
>
<div className={styles.header}>
<HomeHeader />
</div>
{portraitVisible && (
- <div className={styles.speech} data-collapsed={railCollapsed}>
+ <div className={styles.speech} data-collapsed={contentCollapsed}>
{/* Keep the agent's line and artwork together in both header layouts. */}
<div className={styles.bubbleSlot}>
<PortraitBubble promo={promo} />
@@ -423,7 +430,7 @@ const Home = memo(() => {
<Flexbox
className={cx(styles.main, styles.content, styles.contentCollapsed)}
- data-rail-collapsed={railCollapsed}
+ data-rail-collapsed={contentCollapsed}
data-testid={'home-main'}
gap={24}
>
@@ -452,13 +459,11 @@ const Home = memo(() => {
id={'home-rail'}
inert={railCollapsed}
>
- <Suspense fallback={null}>
- {/* The inbox reads assistant replies, which carry internal entity
- links; only the acceptance drawer can show a detail here. */}
- <EntityLinkHostProvider portal={HOME_ENTITY_PORTAL_SCOPE}>
- <HomeInbox {...RAIL_INBOX_PROPS} variant={'rail'} />
- </EntityLinkHostProvider>
- </Suspense>
+ {/* The inbox reads assistant replies, which carry internal entity
+ links; only the acceptance drawer can show a detail here. */}
+ <EntityLinkHostProvider portal={HOME_ENTITY_PORTAL_SCOPE}>
+ <HomeInbox {...RAIL_INBOX_PROPS} variant={'rail'} onRailEmptyChange={setRailEmpty} />
+ </EntityLinkHostProvider>
</aside>
)}
diff --git a/src/features/HomeInbox/inboxBlockState.test.ts b/src/features/HomeInbox/inboxBlockState.test.ts
index 5e1c18c6112..6bb7c60d3f4 100644
--- a/src/features/HomeInbox/inboxBlockState.test.ts
+++ b/src/features/HomeInbox/inboxBlockState.test.ts
@@ -25,13 +25,9 @@ describe('resolveInboxBlockState', () => {
expect(resolveInboxBlockState({ ...failed, isMain: true })).toBeNull();
});
- it('drops both states in the rail once news is off, since the rail never shows needs-you', () => {
- expect(
- resolveInboxBlockState({ ...firstLoad, hiddenWidgets: ['news'], hideNeedsYou: true }),
- ).toBeNull();
- expect(
- resolveInboxBlockState({ ...failed, hiddenWidgets: ['news'], hideNeedsYou: true }),
- ).toBeNull();
+ it('never holds the rail, which shows no brief feed of its own', () => {
+ expect(resolveInboxBlockState({ ...firstLoad, hideNeedsYou: true })).toBeNull();
+ expect(resolveInboxBlockState({ ...failed, hideNeedsYou: true })).toBeNull();
});
it('keeps them where needs-you still renders, even with news off', () => {
diff --git a/src/features/HomeInbox/inboxBlockState.ts b/src/features/HomeInbox/inboxBlockState.ts
index fdfb76e5b5f..e54be4d244b 100644
--- a/src/features/HomeInbox/inboxBlockState.ts
+++ b/src/features/HomeInbox/inboxBlockState.ts
@@ -11,9 +11,16 @@ interface InboxBlockStateInput {
isMain?: boolean;
}
+/**
+ * Whether the surface waits on the brief feed. Without needs-you (the rail)
+ * nothing reads it before paint: news has its own day feed and only overlays
+ * read state from briefs. Blocking there held a skeleton over the rail on every
+ * refresh until the persisted feed hydrated (LOBE-15206).
+ */
const isBriefsBlockVisible = (hiddenWidgets: string[], hideNeedsYou?: boolean): boolean =>
- (!hideNeedsYou && isWidgetSectionVisible('needsYou', hiddenWidgets)) ||
- isWidgetSectionVisible('news', hiddenWidgets);
+ !hideNeedsYou &&
+ (isWidgetSectionVisible('needsYou', hiddenWidgets) ||
+ isWidgetSectionVisible('news', hiddenWidgets));
export const resolveInboxBlockState = ({
hasError,
diff --git a/src/features/HomeInbox/index.tsx b/src/features/HomeInbox/index.tsx
index a57e26250ed..22f41242e5a 100644
--- a/src/features/HomeInbox/index.tsx
+++ b/src/features/HomeInbox/index.tsx
@@ -1,7 +1,7 @@
import { ActionIcon, createStaticStyles, cx, Flexbox, Segmented } from '@lobehub/ui';
import dayjs from 'dayjs';
import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
-import { Fragment, memo, type ReactNode, useMemo, useState } from 'react';
+import { Fragment, memo, type ReactNode, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
@@ -55,6 +55,20 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
`,
}));
+/**
+ * Mounted only while the rail has settled with nothing to show, so the page
+ * hears "empty" once the feeds have answered and "not empty" as soon as any
+ * card returns β€” including when the rail unmounts.
+ */
+const RailEmptyReporter = ({ onChange }: { onChange: (empty: boolean) => void }) => {
+ useEffect(() => {
+ onChange(true);
+ return () => onChange(false);
+ }, [onChange]);
+
+ return null;
+};
+
interface InboxSection {
/** Header action revealed on hover (GroupBlock's action slot). */
action?: ReactNode;
@@ -113,6 +127,12 @@ interface HomeInboxProps {
* news) fold into this column instead of disappearing with it.
*/
inlineRail?: boolean;
+ /**
+ * Rail only: told `true` once the rail's feeds have loaded and it has no card
+ * to show, and `false` when a card appears, so the page can hand its space to
+ * the main column without guessing from a loading rail.
+ */
+ onRailEmptyChange?: (empty: boolean) => void;
/** Controlled mine/team scope β€” lets the page share one scope across sibling sections. */
onScopeChange?: (scope: 'mine' | 'team') => void;
scope?: 'mine' | 'team';
@@ -125,6 +145,7 @@ const HomeInbox = memo<HomeInboxProps>((props) => {
hideRunning,
hideUnread,
inlineRail,
+ onRailEmptyChange,
onScopeChange,
scope: controlledScope,
variant = 'default',
@@ -523,13 +544,32 @@ const HomeInbox = memo<HomeInboxProps>((props) => {
if (visibleSections.length === 0) {
if (isMain) return null;
- if (isRail)
- return recommendationsVisible || usageCard ? (
- <Flexbox gap={12}>
- {recommendationsVisible && <Recommendations variant={'rail'} />}
- {usageCard}
- </Flexbox>
- ) : null;
+ if (isRail) {
+ if (recommendationsVisible || usageCard)
+ return (
+ <Flexbox gap={12}>
+ {recommendationsVisible && <Recommendations variant={'rail'} />}
+ {usageCard}
+ </Flexbox>
+ );
+
+ // Still waiting on a feed that may yet fill the rail: keep its place
+ // with the loading skeleton rather than collapse it and slide the page
+ // back when the cards land.
+ const railFeedsSettled =
+ (!showGoals || goals !== undefined || Boolean(goalsSWR.error)) &&
+ (!showRailSections || Boolean(newsSWR.data) || Boolean(newsSWR.error));
+
+ if (!railFeedsSettled)
+ return (
+ <Flexbox gap={12}>
+ <BriefCardSkeleton />
+ <BriefCardSkeleton />
+ </Flexbox>
+ );
+
+ return onRailEmptyChange ? <RailEmptyReporter onChange={onRailEmptyChange} /> : null;
+ }
// With no titled block above it, the bare recommendations list doesn't need
// the full section gap below the input area β€” offset the parent's gap so it