Skip to content

Commit f023c7b

Browse files
committed
feat: load preact/debug in dev by default
`preact/debug` is now imported by the client boot chunk — the first framework code any page with islands runs. It is a top-level `await`, so the import finishes before any island hydrates. `import.meta.env.DEV` is `false` in a production build, so the import is dropped and `preact/debug` never ends up in the shipped bundle.
1 parent 34a17d0 commit f023c7b

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/entrypoints/internal/client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// This module is the client boot chunk — the first framework code every page
2+
// with islands (or client navigation) evaluates. In dev we load
3+
// `preact/debug` here, so it is on by default without the user wiring up an
4+
// `entry.client.ts`. The `await` is what keeps the ordering: the inline boot
5+
// script's `import { boot } from <this chunk>` doesn't resolve until
6+
// `preact/debug` has been imported, so no island renders before it.
7+
//
8+
// `import.meta.env.DEV` is statically `false` in a production build, so the
9+
// import is dropped and `preact/debug` never ends up in the shipped bundle.
10+
// The `typeof` guard matches the rest of the client runtime — it keeps the
11+
// module evaluable outside a Vite pipeline (e.g. plain Vitest imports).
12+
if (typeof import.meta.env !== "undefined" && import.meta.env.DEV) {
13+
await import("preact/debug");
14+
}
15+
116
export { signal } from "@preact/signals";
217
export {
318
boot,

tests/e2e/preact-debug.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
// The dev server pulls in `preact/debug` from the client boot chunk, so
4+
// Preact's development warnings and the devtools bridge are on without the
5+
// app wiring up an `entry.client.ts`. (These tests run against `vite dev`.)
6+
test("preact/debug is loaded on a page with islands in dev", async ({ page }) => {
7+
const requested: string[] = [];
8+
page.on("request", (req) => requested.push(req.url()));
9+
10+
await page.goto("/islands");
11+
// Hydration finishing means the boot chunk evaluated — including its
12+
// top-level `await import("preact/debug")`.
13+
await expect(page.locator("#counter")).toHaveAttribute("data-hydrated", "true");
14+
15+
expect(requested.some((url) => /preact[_/]debug/.test(url))).toBe(true);
16+
});

0 commit comments

Comments
 (0)