Skip to content

Commit 12294b6

Browse files
claude: Fix bundler async cycles by making CRI client import dynamic
Breaks the async propagation chain from hash.ts by converting the static import of withCriClient to a dynamic import. This prevents esbuild from marking core/handlers/base.ts as async, which was causing it to propagate async to 14 cyclic files, generating invalid bundle code. The ILP optimizer identified this single import as the optimal break point affecting all 14 async propagation chains. Changes: - Remove static import of withCriClient from core/cri/cri.ts - Add getCriClient() helper function with dynamic import - Update extractHtml() to use getCriClient() - Update createPngsFromHtml() to use getCriClient() Result: Bundle builds successfully with no async cycle errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3a81483 commit 12294b6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core/handlers/base.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ import { figuresDir, inputFilesDir } from "../render.ts";
7878
import { ensureDirSync } from "../../deno_ral/fs.ts";
7979
import { mappedStringFromFile } from "../mapped-text.ts";
8080
import { error } from "../../deno_ral/log.ts";
81-
import { withCriClient } from "../cri/cri.ts";
8281
import { normalizePath } from "../path.ts";
8382
import {
8483
InvalidShortcodeError,
@@ -89,6 +88,12 @@ import { LocalizedError } from "../lib/located-error.ts";
8988

9089
const handlers: Record<string, LanguageHandler> = {};
9190

91+
// Dynamic import helper for CRI client to break async propagation chain
92+
async function getCriClient() {
93+
const { withCriClient } = await import("../cri/cri.ts");
94+
return withCriClient;
95+
}
96+
9297
let globalFigureCounter: Record<string, number> = {};
9398

9499
export function resetFigureCounter() {
@@ -143,6 +148,7 @@ function makeHandlerContext(
143148
Deno.writeTextFileSync(fileName, content);
144149
const url = `file://${fileName}`;
145150

151+
const withCriClient = await getCriClient();
146152
return await withCriClient(async (client) => {
147153
await client.open(url);
148154
return await client.contents(selector);
@@ -177,6 +183,7 @@ function makeHandlerContext(
177183
Deno.writeTextFileSync(fileName, content);
178184
const url = `file://${fileName}`;
179185

186+
const withCriClient = await getCriClient();
180187
const { elements, images } = await withCriClient(async (client) => {
181188
await client.open(url);
182189
const elements = await client.contents(selector);

0 commit comments

Comments
 (0)