perf(studio): load import organization tools on demand
This commit is contained in:
1 parent
f7b9b55700
commit
dd7613850e
3 files changed
+74
-22
No files matched your search
@@ -7,7 +7,6 @@ import {
|
|||||||
ClipboardCheck,
|
ClipboardCheck,
|
||||||
Copy,
|
Copy,
|
||||||
Dumbbell,
|
Dumbbell,
|
||||||
FolderTree,
|
|
||||||
Image as ImageIcon,
|
Image as ImageIcon,
|
||||||
type LucideIcon,
|
type LucideIcon,
|
||||||
Puzzle,
|
Puzzle,
|
||||||
@@ -19,7 +18,7 @@ import {
|
|||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { CatalogManagerDialog } from "@/app/admin/catalog/catalog-manager-dialog-wrapper";
|
import { CatalogManagerDialog } from "@/app/admin/catalog/catalog-manager-dialog-wrapper";
|
||||||
import { OrganizeImportsDialog } from "@/components/admin/studio/organize-imports-dialog";
|
import { OrganizeImportsLauncher } from "@/components/admin/studio/organize-imports-launcher";
|
||||||
import Link from "@/components/link";
|
import Link from "@/components/link";
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
@@ -115,7 +114,6 @@ export function StudioLayoutClient({
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const pathname = usePathname() ?? "";
|
const pathname = usePathname() ?? "";
|
||||||
const [organizeOpen, setOrganizeOpen] = useState(false);
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-[calc(100dvh-7rem)] min-h-[600px] min-w-0 flex-col overflow-hidden rounded-xl border border-[var(--admin-border)] bg-[var(--admin-canvas)] text-[var(--admin-text)]">
|
<div className="flex h-[calc(100dvh-7rem)] min-h-[600px] min-w-0 flex-col overflow-hidden rounded-xl border border-[var(--admin-border)] bg-[var(--admin-canvas)] text-[var(--admin-text)]">
|
||||||
<nav
|
<nav
|
||||||
@@ -153,14 +151,7 @@ export function StudioLayoutClient({
|
|||||||
canEdit
|
canEdit
|
||||||
triggerLabel="Catalog manager"
|
triggerLabel="Catalog manager"
|
||||||
/>
|
/>
|
||||||
<button
|
<OrganizeImportsLauncher />
|
||||||
type="button"
|
|
||||||
onClick={() => setOrganizeOpen(true)}
|
|
||||||
className="flex min-h-10 items-center gap-2 rounded-lg px-3 text-sm font-medium text-[var(--admin-text-muted)] hover:bg-[var(--admin-accent)]/10"
|
|
||||||
>
|
|
||||||
<FolderTree size={16} />
|
|
||||||
Organize imports
|
|
||||||
</button>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<StudioMenu
|
<StudioMenu
|
||||||
@@ -176,12 +167,6 @@ export function StudioLayoutClient({
|
|||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<div className="min-h-0 min-w-0 flex-1 overflow-auto">{children}</div>
|
<div className="min-h-0 min-w-0 flex-1 overflow-auto">{children}</div>
|
||||||
{canEditCatalog && (
|
|
||||||
<OrganizeImportsDialog
|
|
||||||
open={organizeOpen}
|
|
||||||
onOpenChange={setOrganizeOpen}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { FolderTree } from "lucide-react";
|
||||||
|
import { lazy, Suspense, useState } from "react";
|
||||||
|
import { StudioPanelLoading } from "./studio-panel-loading";
|
||||||
|
|
||||||
|
const OrganizeImportsDialog = lazy(() =>
|
||||||
|
import("./organize-imports-dialog").then((module) => ({
|
||||||
|
default: module.OrganizeImportsDialog,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
export function OrganizeImportsLauncher() {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [requested, setRequested] = useState(false);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
setRequested(true);
|
||||||
|
setOpen(true);
|
||||||
|
}}
|
||||||
|
className="flex min-h-10 items-center gap-2 rounded-lg px-3 text-sm font-medium text-[var(--admin-text-muted)] hover:bg-[var(--admin-accent)]/10"
|
||||||
|
>
|
||||||
|
<FolderTree size={16} />
|
||||||
|
Organize imports
|
||||||
|
</button>
|
||||||
|
{requested && (
|
||||||
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
open ? <StudioPanelLoading onClose={() => setOpen(false)} /> : null
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<OrganizeImportsDialog open={open} onOpenChange={setOpen} />
|
||||||
|
</Suspense>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,8 +2,7 @@ import path from "node:path";
|
|||||||
import { build } from "esbuild";
|
import { build } from "esbuild";
|
||||||
import { expect, it } from "vitest";
|
import { expect, it } from "vitest";
|
||||||
|
|
||||||
it("keeps scale preview and generation outside the initial Nitro editor bundle", async () => {
|
async function bundleInputs(entry: string) {
|
||||||
const entry = "src/app/admin/import/furni/nitro-editor-dialog.tsx";
|
|
||||||
const result = await build({
|
const result = await build({
|
||||||
entryPoints: [entry],
|
entryPoints: [entry],
|
||||||
bundle: true,
|
bundle: true,
|
||||||
@@ -14,6 +13,17 @@ it("keeps scale preview and generation outside the initial Nitro editor bundle",
|
|||||||
metafile: true,
|
metafile: true,
|
||||||
packages: "external",
|
packages: "external",
|
||||||
alias: { "@": path.resolve("src") },
|
alias: { "@": path.resolve("src") },
|
||||||
|
plugins: [
|
||||||
|
{
|
||||||
|
name: "server-action-boundary",
|
||||||
|
setup(builder) {
|
||||||
|
builder.onResolve({ filter: /^@\/actions\// }, ({ path }) => ({
|
||||||
|
path,
|
||||||
|
external: true,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
const outputs = result.metafile.outputs;
|
const outputs = result.metafile.outputs;
|
||||||
const start = Object.keys(outputs).find(
|
const start = Object.keys(outputs).find(
|
||||||
@@ -34,13 +44,30 @@ it("keeps scale preview and generation outside the initial Nitro editor bundle",
|
|||||||
const initialInputs = new Set(
|
const initialInputs = new Set(
|
||||||
[...seen].flatMap((key) => Object.keys(outputs[key].inputs)),
|
[...seen].flatMap((key) => Object.keys(outputs[key].inputs)),
|
||||||
);
|
);
|
||||||
|
return { initialInputs, inputs: Object.keys(result.metafile.inputs) };
|
||||||
|
}
|
||||||
|
|
||||||
|
it("keeps scale preview and generation outside the initial Nitro editor bundle", async () => {
|
||||||
|
const { initialInputs, inputs } = await bundleInputs(
|
||||||
|
"src/app/admin/import/furni/nitro-editor-dialog.tsx",
|
||||||
|
);
|
||||||
for (const name of [
|
for (const name of [
|
||||||
"nitro-quality-panel.tsx",
|
"nitro-quality-panel.tsx",
|
||||||
"nitro-scale32-generator.tsx",
|
"nitro-scale32-generator.tsx",
|
||||||
]) {
|
]) {
|
||||||
expect(
|
expect(inputs.some((input) => input.endsWith(name))).toBe(true);
|
||||||
Object.keys(result.metafile.inputs).some((input) => input.endsWith(name)),
|
expect([...initialInputs].some((input) => input.endsWith(name))).toBe(
|
||||||
).toBe(true);
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, 30_000);
|
||||||
|
|
||||||
|
it("loads import organization and its icon picker only when requested in Studio", async () => {
|
||||||
|
const { initialInputs, inputs } = await bundleInputs(
|
||||||
|
"src/app/admin/studio/studio-layout-client.tsx",
|
||||||
|
);
|
||||||
|
for (const name of ["organize-imports-dialog.tsx", "icon-picker.tsx"]) {
|
||||||
|
expect(inputs.some((input) => input.endsWith(name))).toBe(true);
|
||||||
expect([...initialInputs].some((input) => input.endsWith(name))).toBe(
|
expect([...initialInputs].some((input) => input.endsWith(name))).toBe(
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user