Skip to content

Dynamically import PlateEditor for slide-out panels #1014

@MODSetter

Description

@MODSetter

Description

The PlateEditor (rich text editor with many plugins) is statically imported in several panel components that are hidden behind user interactions (clicking "Edit", opening reports, etc.). This adds ~200KB+ to the route chunk even though most users never open these panels in a given session.

Vercel React Best Practices Rule: bundle-dynamic-imports (2.4)

Files to change

  • surfsense_web/components/editor-panel/editor-panel.tsx
  • surfsense_web/components/report-panel/report-panel.tsx
  • surfsense_web/components/hitl-edit-panel/hitl-edit-panel.tsx

What to do

For each file, replace the static import of PlateEditor with a dynamic import:

import dynamic from "next/dynamic";
import { Skeleton } from "@/components/ui/skeleton";

const PlateEditor = dynamic(
  () => import("@/components/editor/plate-editor").then(m => ({ default: m.PlateEditor })),
  { ssr: false, loading: () => <Skeleton className="h-64 w-full" /> }
);

Also check RightPanel.tsx — if it directly imports EditorPanel, ReportPanel, or HitlEditPanel, those imports should also be dynamic since the right panel starts collapsed.

Acceptance criteria

  • PlateEditor loads on demand when a panel is opened
  • A skeleton/loading state shows briefly while the editor loads
  • Editor functionality (typing, formatting, saving) works after loading
  • Main chat page bundle size is reduced (verify with next build)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions