1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53import { test, expect } from "@playwright/test";
const BASE = "http://localhost:4174";
test.describe("Loading boundaries (loading.tsx)", () => {
test("slow page eventually renders content", async ({ page }) => {
await page.goto(`${BASE}/slow`);
// The page should render โ loading.tsx should resolve to the actual page
await expect(page.locator("h1")).toHaveText("Slow Page", {
timeout: 10_000,
});
await expect(page.locator("main > p")).toHaveText(
"This page has a loading boundary.",
);
});
test("slow page serves HTML response", async ({ page }) => {
const response = await page.goto(`${BASE}/slow`);
expect(response?.status()).toBe(200);
expect(response?.headers()["content-type"]).toContain("text/html");
});
/**
* OpenNext Compat: loading.tsx Suspense visibility timing
*
* Ported from: https://github.com/opennextjs/opennextjs-cloudflare/blob/main/examples/e2e/app-router/e2e/ssr.test.ts
*
* OpenNext verifies that loading.tsx boundary is visible BEFORE the page content
* resolves. This confirms Suspense streaming works correctly โ the loading state
* is sent immediately in the initial HTML shell, then replaced by the resolved content.
*
* The slow page has a 2s async delay. The loading.tsx fallback should appear in
* the initial streamed HTML shell before the page component resolves.
*/
test("loading boundary is visible before content resolves", async ({
page,
}) => {
// Ref: opennextjs-cloudflare ssr.test.ts "Server Side Render and loading.tsx"
// Navigate to slow page โ loading.tsx should show first due to 2s server delay
void page.goto(`${BASE}/slow`);
// loading.tsx fallback should appear quickly in the streamed shell
const loading = page.locator("#loading-fallback");
await expect(loading).toBeVisible({ timeout: 5_000 });
// Then the actual page content should resolve
await expect(page.locator("h1")).toHaveText("Slow Page", {
timeout: 10_000,
});
});
});