Thanks to visit codestin.com
Credit goes to github.com

Skip to content

debugging #328 #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches: [main]
pull_request:

env:
NEXT_PRIVATE_DEBUG_CACHE: 1

jobs:
test:
timeout-minutes: 30
Expand Down Expand Up @@ -37,3 +40,10 @@ jobs:
name: playwright-report
path: ./**/playwright-report
retention-days: 1

- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: ./**/e2e/app-router/.open-next
retention-days: 1
4 changes: 3 additions & 1 deletion examples/common/config-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare const process: typeof nodeProcess;
export function configurePlaywright(
app: AppName,
{
testDir = "./",
// Do we run on CI?
isCI = false,
// Do we run on workers (`wrangler dev`) or on Node (`next dev`)
Expand Down Expand Up @@ -56,7 +57,7 @@ export function configurePlaywright(
* See https://playwright.dev/docs/test-configuration.
*/
return defineConfig({
testDir: "./",
testDir,
/* ignore runtime specific tests */
testIgnore: isWorker ? "*next.spec.ts" : "*cloudflare.spec.ts",
/* Run tests in files in parallel */
Expand Down Expand Up @@ -85,6 +86,7 @@ export function configurePlaywright(
url: baseURL,
reuseExistingServer: !isCI,
timeout,
stdout: "pipe",
},
});
}
38 changes: 38 additions & 0 deletions examples/e2e/app-router/e2e/only/ssr.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// NOTE: loading.tsx is currently broken on open - next
// This works locally but not on deployed apps

import { expect, test } from "@playwright/test";

// NOTE: We don't await page load b/c we want to see the Loading page
// loading.tsx doesn't currently work: https://github.com/opennextjs/opennextjs-cloudflare/issues/313
test.skip("Server Side Render and loading.tsx", async ({ page }) => {
test.setTimeout(600000);
await page.goto("/");
await page.getByRole("link", { name: "SSR" }).click();
await page.waitForURL("/ssr");

let loading: any;
let lastTime = "";

for (let i = 0; i < 5; i++) {
void page.reload();

loading = page.getByText("Loading...");
await expect(loading).toBeVisible();
const el = page.getByText("Time:");
await expect(el).toBeVisible();
const time = await el.textContent();
expect(time).not.toEqual(lastTime);
lastTime = time!;
await page.waitForTimeout(1000);
}
});

test("Fetch cache properly cached", async ({ page }) => {
await page.goto("/ssr");
const originalDate = await page.getByText("Cached fetch:").textContent();
await page.waitForTimeout(2000);
await page.reload();
const newDate = await page.getByText("Cached fetch:").textContent();
expect(originalDate).toEqual(newDate);
});
6 changes: 5 additions & 1 deletion examples/e2e/app-router/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { configurePlaywright } from "../../../common/config-e2e";

export default configurePlaywright("app-router", { isCI: !!process.env.CI, multipleBrowsers: false });
export default configurePlaywright("app-router", {
testDir: "./only",
isCI: !!process.env.CI,
multipleBrowsers: false,
});
2 changes: 1 addition & 1 deletion examples/e2e/app-router/e2e/ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test.skip("Server Side Render and loading.tsx", async ({ page }) => {
}
});

test.skip("Fetch cache properly cached", async ({ page }) => {
test("Fetch cache properly cached", async ({ page }) => {
await page.goto("/ssr");
const originalDate = await page.getByText("Cached fetch:").textContent();
await page.waitForTimeout(2000);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
},
"scripts": {
"fix": "pnpm prettier:fix && pnpm lint:fix",
"build": "pnpm --filter cloudflare build",
"test": "pnpm -r test",
"e2e": "pnpm build && pnpm -r e2e",
"e2e:dev": "pnpm build && pnpm -r e2e:dev",
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write .",
"lint:check": "pnpm -r lint:check",
Expand All @@ -22,6 +18,10 @@
"code:checks": "pnpm prettier:check && pnpm lint:check && pnpm ts:check",
"install-playwright": "playwright install --with-deps",
"postinstall": "pnpm --filter cloudflare build",
"test": "pnpm -r test",
"build": "pnpm --filter cloudflare build",
"e2e": "pnpm build && pnpm -F app-router e2e",
"e2e:dev": "pnpm build && pnpm -r e2e:dev",
"benchmark": "pnpm run --filter benchmarking benchmark"
}
}
19 changes: 17 additions & 2 deletions packages/cloudflare/src/api/kvCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ export const STATUS_DELETED = 1;
class Cache implements IncrementalCache {
readonly name = "cloudflare-kv";

constructor() {
console.error(`========> cloudflare-kv Cache INIT`);
}

async get<IsFetch extends boolean = false>(
key: string,
isFetch?: IsFetch
): Promise<WithLastModified<CacheValue<IsFetch>>> {
console.error(`========> KVCache.get (${key})`);

const cfEnv = getCloudflareContext().env;
const kv = cfEnv.NEXT_CACHE_WORKERS_KV;
const assets = cfEnv.ASSETS;
Expand All @@ -39,15 +45,18 @@ class Cache implements IncrementalCache {
} | null = null;

if (kv) {
console.error(` from KV`);
this.debug(`- From KV`);
const kvKey = this.getKVKey(key, isFetch);
entry = await kv.get(kvKey, "json");
console.error(` does entry from KV exist? ${!!entry}`);
if (entry?.status === STATUS_DELETED) {
return {};
}
}

if (!entry && assets) {
console.error(` from assets`);
this.debug(`- From Assets`);
const url = this.getAssetUrl(key, isFetch);
const response = await assets.fetch(url);
Expand All @@ -61,10 +70,12 @@ class Cache implements IncrementalCache {
lastModified: (globalThis as { __BUILD_TIMESTAMP_MS__?: number }).__BUILD_TIMESTAMP_MS__,
};
}
console.error(` does entry from assets exist? ${!!entry}`);
}
this.debug(entry ? `-> hit` : `-> miss`);
return { value: entry?.value, lastModified: entry?.lastModified };
} catch {
console.error(` ERROR! FAILED TO GET Cache`);
throw new RecoverableError(`Failed to get cache [${key}]`);
}
}
Expand All @@ -74,13 +85,16 @@ class Cache implements IncrementalCache {
value: CacheValue<IsFetch>,
isFetch?: IsFetch
): Promise<void> {
console.error(`========> KVCache.set (${key})`);

const kv = getCloudflareContext().env.NEXT_CACHE_WORKERS_KV;

if (!kv) {
console.error(` NO KV!`);
throw new IgnorableError(`No KVNamespace`);
}

this.debug(`Set ${key}`);
console.error(` from KV`);

try {
const kvKey = this.getKVKey(key, isFetch);
Expand All @@ -97,6 +111,7 @@ class Cache implements IncrementalCache {
})
);
} catch {
console.error(` ERROR! FAILED TO SET Cache`);
throw new RecoverableError(`Failed to set cache [${key}]`);
}
}
Expand Down Expand Up @@ -131,7 +146,7 @@ class Cache implements IncrementalCache {

protected debug(...args: unknown[]) {
if (process.env.NEXT_PRIVATE_DEBUG_CACHE) {
console.log(`[Cache ${this.name}] `, ...args);
console.error(`[Cache ${this.name}] `, ...args);
}
}

Expand Down
Loading