mirror of
https://github.com/usememos/memos.git
synced 2026-11-19 10:29:11 +01:00
fix(web): render the Home composer with the page
The editing session became a lazy chunk in #6481, so a signed-in user's Home showed a blank card until the chunk arrived, then the feed jumped up 18px when the real composer replaced it. The Home and Explore routes of a signed-in user now load the session's code together with the page, so the composer renders with the page as it did before the split; visitors keep the lighter page. Where a draft can still suspend, the fallback is a still of the empty composer with the same frame, placeholder line and toolbar height, so nothing moves when the session takes its place.
This commit is contained in:
@@ -162,8 +162,14 @@ const MemoEditorDraft = ({ draft, ...editing }: MemoEditorDraftProps) => {
|
||||
const identity: MemoEditIdentity = draft.parent
|
||||
? { kind: "comment", parent: draft.parent }
|
||||
: { kind: "new", scope: draft.scope ?? "default", space: draft.space };
|
||||
// While the session's code loads, a still of the empty composer: the same frame, the
|
||||
// placeholder line and the toolbar's height, so the page below does not move when the
|
||||
// session takes its place.
|
||||
const fallback = editing.frameless ? null : (
|
||||
<div aria-hidden className={cn("w-full min-h-28 rounded-lg border border-border/70 bg-card", editing.className)} />
|
||||
<div aria-hidden className={cn("flex w-full flex-col gap-2 rounded-lg border border-border/70 bg-card px-4 py-3", editing.className)}>
|
||||
<div className="w-full text-base leading-6 text-muted-foreground">{editing.placeholder ?? " "}</div>
|
||||
<div className="h-9 w-full" />
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<Suspense fallback={fallback}>
|
||||
|
||||
@@ -61,7 +61,7 @@ Hosts of a new top-level memo pass `useMemoSuggestions()` into `suggestions`; ed
|
||||
- **Inline** (Home, panels): the session brings its own frame. The + menu offers focus mode, which expands it over the page; the exit button minimizes it back.
|
||||
- **Hosted** (`onFocusModeExit`): a host presents the session full-screen and owns that frame (`contexts/GlobalMemoEditorContext.tsx`). It mounts straight into focus mode and exits by calling back to dismiss the host.
|
||||
|
||||
The session's code is a chunk of its own, loaded when a memo is first edited or composed, and renders without suspending once loaded; a host that knows an editor is coming calls `preloadMemoEditing()`.
|
||||
The session's code is a chunk of its own, loaded when a memo is first edited or composed, and renders without suspending once loaded. A host that knows an editor is coming calls `preloadMemoEditing()`: the router loads it with the Home page for a signed-in user, so the composer renders with the page, and the comment section loads it while the pointer is on its button. Until it is loaded a new draft shows a still of the empty composer, the same frame, placeholder line and toolbar height, so nothing moves when the session takes its place.
|
||||
|
||||
### Destination and visibility
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createBrowserRouter, Navigate, type RouteObject, useLocation } from "react-router-dom";
|
||||
import App from "@/App";
|
||||
import { ChunkLoadErrorFallback } from "@/components/ErrorBoundary";
|
||||
import { preloadMemoEditing } from "@/components/MemoEditor";
|
||||
import { useAuth } from "@/contexts/AuthContext";
|
||||
import useCurrentUser from "@/hooks/useCurrentUser";
|
||||
import MainLayout from "@/layouts/MainLayout";
|
||||
@@ -18,6 +19,9 @@ const AuthCallback = lazyWithReload(() => import("@/pages/AuthCallback"));
|
||||
const MemoMap = lazyWithReload(() => import("@/pages/Map"));
|
||||
const Calendar = lazyWithReload(() => import("@/pages/Calendar"));
|
||||
const Home = lazyWithReload(() => import("@/pages/Home"));
|
||||
// A signed-in user's Home composes at once, so the page's code arrives together with the
|
||||
// editing session's and the composer renders with the page, never after it.
|
||||
const ComposingHome = lazyWithReload(() => Promise.all([import("@/pages/Home"), preloadMemoEditing()]).then(([page]) => page));
|
||||
const Inboxes = lazyWithReload(() => import("@/pages/Inboxes"));
|
||||
const MemoDetail = lazyWithReload(() => import("@/pages/MemoDetail"));
|
||||
const NotFound = lazyWithReload(() => import("@/pages/NotFound"));
|
||||
@@ -36,14 +40,15 @@ const HomeRoute = () => {
|
||||
if (!currentUser && !getCollectionCreator(location.search)) {
|
||||
return <Navigate to={{ pathname: ROUTES.EXPLORE, search: location.search, hash: location.hash }} replace />;
|
||||
}
|
||||
return <Home />;
|
||||
return currentUser ? <ComposingHome /> : <Home />;
|
||||
};
|
||||
|
||||
const ExploreRoute = () => {
|
||||
const currentUser = useCurrentUser();
|
||||
const location = useLocation();
|
||||
const search = withCollectionCreator(location.search);
|
||||
if (search !== location.search) return <Navigate to={{ pathname: location.pathname, search, hash: location.hash }} replace />;
|
||||
return <Home />;
|
||||
return currentUser ? <ComposingHome /> : <Home />;
|
||||
};
|
||||
|
||||
// Backward compatibility alias.
|
||||
|
||||
Reference in New Issue
Block a user