Skip to content

Commit 72326a3

Browse files
fix(cli): a render's lint runs at normal priority, so a busy Windows PC no longer stalls it (#7268)
1 parent 4935d67 commit 72326a3

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎packages/cli/src/commands/preview.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ async function printStartupLint(dir: string, verbose: boolean): Promise<void> {
627627
try {
628628
const lintResult = await runRenderSetupWorker<ProjectLintResult>(
629629
"lint",
630-
{ projectDir: dir },
630+
{ projectDir: dir, background: true },
631631
{ maxBufferBytes: 8 * 1024 * 1024 },
632632
);
633633
if (lintResult.totalErrors === 0 && lintResult.totalWarnings === 0) return;

‎packages/cli/src/renderSetupWorker.priority.test.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ beforeEach(() => {
1212
vi.resetModules();
1313
os.setPriority.mockReset();
1414
process.argv[2] = "lint";
15-
process.env.HYPERFRAMES_RENDER_SETUP_INPUT = JSON.stringify({ projectDir: "/project" });
15+
process.env.HYPERFRAMES_RENDER_SETUP_INPUT = JSON.stringify({
16+
projectDir: "/project",
17+
background: true,
18+
});
1619
});
1720
afterEach(() => vi.restoreAllMocks());
1821

19-
it("lints at the lowest CPU priority so it never competes with a Studio boot", async () => {
22+
it("a background lint runs at the lowest CPU priority so it never competes with a Studio boot", async () => {
2023
const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
2124

2225
await import("./renderSetupWorker.js");
@@ -25,6 +28,17 @@ it("lints at the lowest CPU priority so it never competes with a Studio boot", a
2528
expect(write).toHaveBeenCalledWith(expect.stringContaining('{"ok":true}'));
2629
});
2730

31+
// fails without the fix: a render waits on its lint, and at idle priority a busy Windows PC starved it for minutes.
32+
it("a render's lint keeps normal priority", async () => {
33+
process.env.HYPERFRAMES_RENDER_SETUP_INPUT = JSON.stringify({ projectDir: "/project" });
34+
const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
35+
36+
await import("./renderSetupWorker.js");
37+
38+
expect(os.setPriority).not.toHaveBeenCalled();
39+
expect(write).toHaveBeenCalledWith(expect.stringContaining('{"ok":true}'));
40+
});
41+
2842
const nodeSystemErrorWithOsCodeInInfo = (code: string) =>
2943
Object.assign(new Error(`A system error occurred: uv_os_setpriority returned ${code}`), {
3044
code: "ERR_SYSTEM_ERROR",

‎packages/cli/src/renderSetupWorker.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ async function runMode(): Promise<unknown> {
3636
if (mode === "browser") return ensureBrowser(input);
3737
if (mode === "browser-install") return runBrowserInstall(input);
3838
if (mode === "lint") {
39-
// Nobody waits on a background lint the way they wait on a Studio boot, so it takes idle CPU only.
40-
lowerPriority();
39+
// A background lint (Studio's, preview's) takes idle CPU only; a render waits on its lint, so that one does not.
40+
if (input.background) lowerPriority();
4141
return lintProject(
4242
input.projectDir,
4343
input.entryFile,

‎packages/cli/src/server/studioServer.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
593593
lintProject: (dir: string) =>
594594
runRenderSetupWorker<ProjectLintResult>(
595595
"lint",
596-
{ projectDir: dir, host: "studio" },
596+
{ projectDir: dir, host: "studio", background: true },
597597
{ maxBufferBytes: 8 * 1024 * 1024 },
598598
),
599599

0 commit comments

Comments
 (0)