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
@@ -2,8 +2,7 @@ import path from "node:path";
|
||||
import { build } from "esbuild";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
it("keeps scale preview and generation outside the initial Nitro editor bundle", async () => {
|
||||
const entry = "src/app/admin/import/furni/nitro-editor-dialog.tsx";
|
||||
async function bundleInputs(entry: string) {
|
||||
const result = await build({
|
||||
entryPoints: [entry],
|
||||
bundle: true,
|
||||
@@ -14,6 +13,17 @@ it("keeps scale preview and generation outside the initial Nitro editor bundle",
|
||||
metafile: true,
|
||||
packages: "external",
|
||||
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 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(
|
||||
[...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 [
|
||||
"nitro-quality-panel.tsx",
|
||||
"nitro-scale32-generator.tsx",
|
||||
]) {
|
||||
expect(
|
||||
Object.keys(result.metafile.inputs).some((input) => input.endsWith(name)),
|
||||
).toBe(true);
|
||||
expect(inputs.some((input) => input.endsWith(name))).toBe(true);
|
||||
expect([...initialInputs].some((input) => input.endsWith(name))).toBe(
|
||||
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(
|
||||
false,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user