Files
lobehub__lobehub/plugins/vite/devLoadingProgress.test.ts
Innei 2933b9fcc5 ⚡️ perf(desktop): show the main window on first paint, compile cache, dev progress (#19429)
* ⚡️ perf(desktop): show the main window on the loading screen's first paint

`ready-to-show` only fires with the `load` event for the desktop entry, which
lands ~250ms after the static loading screen has actually painted. The preload
now reports that first paint (double rAF after `#loading-screen` enters the
DOM) and the main process shows the window on whichever signal arrives first.

Measured on the packaged app (warm start, window creation = 0): window visible
at +140ms instead of +370ms, with the loading screen already painted.

Claude-Session: https://claude.ai/code/session_012z4cpfrWDXZDtNgT4uJKoS

* ⚡️ perf(desktop): enable the V8 compile cache for the main process bundle

Injected as an entry banner because rolldown hoists chunk requires above any
statement in the entry source, so `main-app` would otherwise load uncached.
Main bundle load 55ms → 37ms warm; exec → main.js ~10ms faster on a
packaged build.

Claude-Session: https://claude.ai/code/session_012z4cpfrWDXZDtNgT4uJKoS

* ✨ feat(desktop): show Vite transform progress on the dev loading screens

A cold `bun run dev` sits on the loading logo for 10s+ while Vite transforms
thousands of modules. A serve-only plugin streams the transform count and the
current file over the HMR socket, and an injected client renders it at the
bottom of the window for as long as any boot placeholder (`#loading-screen`,
`#boot-shell`, `#app-shell-fallback`) is on screen.

Claude-Session: https://claude.ai/code/session_012z4cpfrWDXZDtNgT4uJKoS
2026-09-11 15:50:00 +08:00

60 lines
1.6 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { devLoadingProgress } from './devLoadingProgress';
const createServer = (server: Record<string, unknown> = {}) => ({
config: {
root: '/repo',
server: {
hmr: { clientPort: 5173, host: '127.0.0.1' },
host: '127.0.0.1',
port: 5173,
...server,
},
},
hot: { send: vi.fn() },
});
const setup = (server = createServer()) => {
const plugin = devLoadingProgress() as any;
plugin.configureServer(server);
return { plugin, server };
};
describe('devLoadingProgress', () => {
it('injects a client script pointing at the HMR websocket', () => {
const { plugin } = setup();
const [tag] = plugin.transformIndexHtml();
expect(tag.tag).toBe('script');
expect(tag.children).toContain('"ws://127.0.0.1:5173"');
expect(tag.children).toContain('loading-dev-progress');
});
it('injects nothing when HMR is disabled', () => {
const { plugin } = setup(createServer({ hmr: false }));
expect(plugin.transformIndexHtml()).toEqual([]);
});
it('batches transforms into one throttled broadcast with root-relative ids', () => {
vi.useFakeTimers();
const { plugin, server } = setup();
plugin.transform('', '/repo/src/a.tsx?v=1');
plugin.transform('', '/repo/src/b.tsx');
expect(server.hot.send).not.toHaveBeenCalled();
vi.runAllTimers();
expect(server.hot.send).toHaveBeenCalledTimes(1);
expect(server.hot.send).toHaveBeenCalledWith({
data: { count: 2, file: 'src/b.tsx' },
event: 'lobe:dev-loading-progress',
type: 'custom',
});
vi.useRealTimers();
});
});