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: unblock canary CI after the Canvas runtime landed (#21402)

Lobehub Coder98b57634e673
diff --git a/plugins/vite/sharedRendererConfig.test.ts b/plugins/vite/sharedRendererConfig.test.ts
index 409ca17062a..05bd756b398 100644
--- a/plugins/vite/sharedRendererConfig.test.ts
+++ b/plugins/vite/sharedRendererConfig.test.ts
@@ -423,4 +423,24 @@ describe('createSharedRolldownOutput', () => {
expect(output.codeSplitting).not.toHaveProperty('includeDependenciesRecursively');
expect((output.codeSplitting.groups as OutputGroup[]).some((g) => 'tags' in g)).toBe(false);
});
+
+ // Regression: base.css (which styles <body>) shared a chunk with modules the
+ // App's lazy chunks import, so loading Home restyled the App's body.
+ it('gives canvas runtime sources a chunk of their own, apart from modules the App shares', () => {
+ const entry = '/repo/packages/canvas-runtime/src/index.tsx';
+ const base = '/repo/packages/canvas-runtime/src/base.css';
+ const shared = '/repo/packages/canvas/src/index.ts';
+ const graph: Record<string, string[]> = { [base]: [], [entry]: [base, shared], [shared]: [] };
+ const ctx = { getModuleInfo: (id: string) => ({ importedIds: graph[id] }) };
+ const chunkOf = (id: string) =>
+ groups({ initialEntries: { runtime: entry } })
+ .filter((g) => (typeof g.test === 'function' ? g.test(id) : (g.test?.test(id) ?? true)))
+ .sort((a, b) => b.priority - a.priority)
+ .map((g) => (typeof g.name === 'function' ? g.name(id, ctx) : g.name))
+ .find(Boolean);
+
+ expect(chunkOf(base)).toBe('canvas-runtime-runtime');
+ expect(chunkOf(entry)).toBe('canvas-runtime-runtime');
+ expect(chunkOf(shared)).toBe('initial-runtime');
+ });
});
diff --git a/plugins/vite/sharedRendererConfig.ts b/plugins/vite/sharedRendererConfig.ts
index 86badc6b627..c2aa3044ede 100644
--- a/plugins/vite/sharedRendererConfig.ts
+++ b/plugins/vite/sharedRendererConfig.ts
@@ -455,6 +455,14 @@ const splitByInitial = (
// entry-set chunking. Requires preserveEntrySignatures: 'allow-extension'.
export const createSharedRolldownOutput = (options: SharedRolldownOutputOptions = {}) => {
const groups: Group[] = [
+ // The canvas runtime's own modules carry page-level CSS (base.css styles
+ // body). App chunks also reuse modules the runtime pulls in, so without a
+ // chunk of its own that CSS would ride along and restyle the App's body.
+ {
+ name: 'canvas-runtime',
+ priority: 4,
+ test: /[\\/]packages[\\/]canvas-runtime[\\/]src[\\/]/,
+ },
{
name: (moduleId: string) => sharedManualChunks(moduleId) ?? null,
priority: 3,