From 44a54280ec857082021722152b0440b6cc2a8146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Thu, 1 May 2025 08:35:13 +0200 Subject: [PATCH 1/4] Upgrade opennext to upcoming version --- bun.lock | 26 +++++++++++++------------- package.json | 2 +- packages/gitbook-v2/package.json | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bun.lock b/bun.lock index d720c44b8..38ae35c92 100644 --- a/bun.lock +++ b/bun.lock @@ -156,7 +156,7 @@ "warn-once": "^0.1.1", }, "devDependencies": { - "@opennextjs/cloudflare": "^1.0.0-beta.3", + "@opennextjs/cloudflare": "https://pkg.pr.new/opennextjs/opennextjs-cloudflare/@opennextjs/cloudflare@a8815be", "@types/rison": "^0.0.9", "gitbook": "*", "postcss": "^8", @@ -791,9 +791,9 @@ "@nodelib/fs.walk": ["@nodelib/fs.walk@1.2.8", "", { "dependencies": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" } }, "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg=="], - "@opennextjs/aws": ["@opennextjs/aws@3.5.7", "", { "dependencies": { "@ast-grep/napi": "^0.35.0", "@aws-sdk/client-cloudfront": "3.398.0", "@aws-sdk/client-dynamodb": "^3.398.0", "@aws-sdk/client-lambda": "^3.398.0", "@aws-sdk/client-s3": "^3.398.0", "@aws-sdk/client-sqs": "^3.398.0", "@node-minify/core": "^8.0.6", "@node-minify/terser": "^8.0.6", "@tsconfig/node18": "^1.0.1", "aws4fetch": "^1.0.18", "chalk": "^5.3.0", "esbuild": "0.19.2", "express": "5.0.1", "path-to-regexp": "^6.3.0", "urlpattern-polyfill": "^10.0.0", "yaml": "^2.7.0" }, "bin": { "open-next": "dist/index.js" } }, "sha512-YjyHJrkIHI7YwQRCp8GjDOudu86oOc1RiwxvBBpPHrplsS18H4ZmkzGggAKhK6B4myGsJQ/q9kNP2TraoZiNzg=="], + "@opennextjs/aws": ["@opennextjs/aws@3.6.0", "", { "dependencies": { "@ast-grep/napi": "^0.35.0", "@aws-sdk/client-cloudfront": "3.398.0", "@aws-sdk/client-dynamodb": "^3.398.0", "@aws-sdk/client-lambda": "^3.398.0", "@aws-sdk/client-s3": "^3.398.0", "@aws-sdk/client-sqs": "^3.398.0", "@node-minify/core": "^8.0.6", "@node-minify/terser": "^8.0.6", "@tsconfig/node18": "^1.0.1", "aws4fetch": "^1.0.18", "chalk": "^5.3.0", "esbuild": "0.19.2", "express": "5.0.1", "path-to-regexp": "^6.3.0", "urlpattern-polyfill": "^10.0.0", "yaml": "^2.7.0" }, "bin": { "open-next": "dist/index.js" } }, "sha512-fLhPgg9ftV8GKNxuoeRJevKa+LIGMMzY9LIGni+5FO9GyhVf0V93j0WTf2x/g9yk5I64hukMWmCqTszitaZ5yg=="], - "@opennextjs/cloudflare": ["@opennextjs/cloudflare@1.0.0-beta.3", "", { "dependencies": { "@dotenvx/dotenvx": "1.31.0", "@opennextjs/aws": "3.5.7", "enquirer": "^2.4.1", "glob": "^11.0.0", "ts-tqdm": "^0.8.6" }, "peerDependencies": { "wrangler": "^3.114.3 || ^4.7.0" }, "bin": { "opennextjs-cloudflare": "dist/cli/index.js" } }, "sha512-qKBXQZhUeQ+iGvfJeF7PO30g59LHnPOlRVZd77zxwn6Uc9C+c0LSwo8N28XRIWyQPkY007rKk9pSIxOrP4MHtQ=="], + "@opennextjs/cloudflare": ["@opennextjs/cloudflare@https://pkg.pr.new/opennextjs/opennextjs-cloudflare/@opennextjs/cloudflare@a8815be", { "dependencies": { "@dotenvx/dotenvx": "1.31.0", "@opennextjs/aws": "3.6.0", "enquirer": "^2.4.1", "glob": "^11.0.0", "ts-tqdm": "^0.8.6" }, "peerDependencies": { "wrangler": "^4.14.0" }, "bin": { "opennextjs-cloudflare": "dist/cli/index.js" } }], "@opentelemetry/api": ["@opentelemetry/api@1.9.0", "", {}, "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg=="], @@ -4077,7 +4077,7 @@ "gaxios/node-fetch": ["node-fetch@2.7.0", "", { "dependencies": { "whatwg-url": "^5.0.0" }, "peerDependencies": { "encoding": "^0.1.0" }, "optionalPeers": ["encoding"] }, "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A=="], - "gitbook-v2/next": ["next@15.4.0-canary.7", "", { "dependencies": { "@next/env": "15.4.0-canary.7", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.4.0-canary.7", "@next/swc-darwin-x64": "15.4.0-canary.7", "@next/swc-linux-arm64-gnu": "15.4.0-canary.7", "@next/swc-linux-arm64-musl": "15.4.0-canary.7", "@next/swc-linux-x64-gnu": "15.4.0-canary.7", "@next/swc-linux-x64-musl": "15.4.0-canary.7", "@next/swc-win32-arm64-msvc": "15.4.0-canary.7", "@next/swc-win32-x64-msvc": "15.4.0-canary.7", "sharp": "^0.34.1" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-ZYjT0iu+4osz8XIlr31MuoXaNQKRU75UcwEgNBt93gftoh6tzV2Mebz6sOGeVReYuYUvYlLJJksMBTNcFcPbSA=="], + "gitbook-v2/next": ["next@15.4.0-canary.17", "", { "dependencies": { "@next/env": "15.4.0-canary.17", "@swc/helpers": "0.5.15", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.4.0-canary.17", "@next/swc-darwin-x64": "15.4.0-canary.17", "@next/swc-linux-arm64-gnu": "15.4.0-canary.17", "@next/swc-linux-arm64-musl": "15.4.0-canary.17", "@next/swc-linux-x64-gnu": "15.4.0-canary.17", "@next/swc-linux-x64-musl": "15.4.0-canary.17", "@next/swc-win32-arm64-msvc": "15.4.0-canary.17", "@next/swc-win32-x64-msvc": "15.4.0-canary.17", "sharp": "^0.34.1" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-AH14xNNvz+6S33AB3TR+VHkS+cnhrzkNeh8TnYpSbtouQqhJtm0lTYjnQTGqa3cHGKMgLI1h13MU724HiJGbcg=="], "global-dirs/ini": ["ini@1.3.7", "", {}, "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ=="], @@ -4969,23 +4969,23 @@ "gaxios/https-proxy-agent/debug": ["debug@4.3.7", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ=="], - "gitbook-v2/next/@next/env": ["@next/env@15.4.0-canary.7", "", {}, "sha512-q8S7f2lQti3Y3gcAPzE8Pj8y0EwiWHVyyilMzoLbDPXGVfxlQhXLRiFdy2cDkKN4DyjGZWDeehEtw4huvJAa3Q=="], + "gitbook-v2/next/@next/env": ["@next/env@15.4.0-canary.17", "", {}, "sha512-k0dqCJhBYqPyRr/i+M9OYEtn9nJuZjJf9y6jVOkwl+xaEr4K6UmIBu6vVfoWitDwPLRj4NgKmHgkH75dPRxAQg=="], - "gitbook-v2/next/@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@15.4.0-canary.7", "", { "os": "darwin", "cpu": "arm64" }, "sha512-+TMxUu5CAWNe+UFRc47BZAXQxCRqZfVbGyCldddiog4MorvL7kBxSd1qlmrwI73fRRKtXkHIH1TaeItyxzC9rQ=="], + "gitbook-v2/next/@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@15.4.0-canary.17", "", { "os": "darwin", "cpu": "arm64" }, "sha512-CX2ZV8DsLjbX6eYf0OhLMfjZnFykwzAcG6gnz9fJdU+l20YvYj5BlWAefSTLncQ6KWq/FLb8XU00PL8ThaGHPg=="], - "gitbook-v2/next/@next/swc-darwin-x64": ["@next/swc-darwin-x64@15.4.0-canary.7", "", { "os": "darwin", "cpu": "x64" }, "sha512-veXp8lg/X/7O+pG9BDQ3OizFz3B40v29jsvEWj+ULY/W8Z6+dCSd5XPP2M8fG/gKKKA0D6L0CnnM2Mj0RRSUJw=="], + "gitbook-v2/next/@next/swc-darwin-x64": ["@next/swc-darwin-x64@15.4.0-canary.17", "", { "os": "darwin", "cpu": "x64" }, "sha512-J2cdOuAAxpVbjk6QRHPtq1hbDXuNIgCGB/G4HvKot71VIKXg/Fb1IaxwFiBYNl0zsRgH5CPO+AO9pUUGwpVPyQ=="], - "gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/swc-linux-arm64-gnu@15.4.0-canary.7", "", { "os": "linux", "cpu": "arm64" }, "sha512-KxNGfW7BO0Z5B9rJyl9p7YVjNrxAhu06mH6h1PSdouZG7YMYpdRCconVXeuBI0PEu6g3ywNrOVxZUk1V6G5u0Q=="], + "gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/swc-linux-arm64-gnu@15.4.0-canary.17", "", { "os": "linux", "cpu": "arm64" }, "sha512-DKUs71Gi/leUH9RrMRamVfxXfOKdNGov7CH1KufeCyKIl9PNQQhP5GMgUk/19nvNmyFV7PjxIXRxElgBzRPtyQ=="], - "gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/swc-linux-arm64-musl@15.4.0-canary.7", "", { "os": "linux", "cpu": "arm64" }, "sha512-THgXgmP/cC4DsNwvC6uqB90CebB7Ep1KyZajQL3fYKT5V4SWr46yngKLyoyJVeAYWJH908MrWddf7Ya/Zq7cyg=="], + "gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/swc-linux-arm64-musl@15.4.0-canary.17", "", { "os": "linux", "cpu": "arm64" }, "sha512-k4tjv818/f2DLmCZOkqTEsnqDpIUeKFb1gH9WnexjfAJLD2RXmb+hde8PDB64/Syf2RdytREdPZBnDs2okxrbQ=="], - "gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/swc-linux-x64-gnu@15.4.0-canary.7", "", { "os": "linux", "cpu": "x64" }, "sha512-kpLB3Jj7fProynQYj2ahFyZlJs0xwm71VzCVrNRu6u7qJGXn6dK5h7+hro8y/y1iqjXWgCLSdxWSHahhWK8XdQ=="], + "gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/swc-linux-x64-gnu@15.4.0-canary.17", "", { "os": "linux", "cpu": "x64" }, "sha512-5vLVdcMKG2iMPTUu0E9aAvVBbEwKJeCA9CGb1hsQuEuTA3N3XntRHvZKj32POTE4jYJeb0DnxEZHli7SiyOBYw=="], - "gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/swc-linux-x64-musl@15.4.0-canary.7", "", { "os": "linux", "cpu": "x64" }, "sha512-rnGAKvl4cWPVV9D+SybWOGijm0VmKXyqQ+IN0A6WDgdlYZAZP0ZnJv/rq7DSvuOh19AXS8UpQc88SelXV/3j3Q=="], + "gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/swc-linux-x64-musl@15.4.0-canary.17", "", { "os": "linux", "cpu": "x64" }, "sha512-N5YAd9chWQdLJayfkgZP+d/daTAWKa2jm0SPNhjZiez88fkoZlBU+GPLsozA7L3RdaqLGqDPrvavylt1Iw0L9Q=="], - "gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/swc-win32-arm64-msvc@15.4.0-canary.7", "", { "os": "win32", "cpu": "arm64" }, "sha512-/PRbn//EuR3UGiquk050gqvjxLliEgGBy1Cx9KkpAT7szaHOBj1mDDQmxMTEhRex4i3YfKGJXWn5mLMCveya6Q=="], + "gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/swc-win32-arm64-msvc@15.4.0-canary.17", "", { "os": "win32", "cpu": "arm64" }, "sha512-URAe7qnVC8tarSBx/V/WDRP3xzkb8tr3m9gEjIYbBBVF64xlzrPshcPe5HIssGjL/5u3NRs9VxgsE9xZ7CcxKA=="], - "gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/swc-win32-x64-msvc@15.4.0-canary.7", "", { "os": "win32", "cpu": "x64" }, "sha512-7a92XL+DlrbWyycCpQjjQMHOrsA0p+VvS7iA2dyi89Xsq0qtOPzFH0Gb56fsjh6M6BQGFhboOSzjmpjlkMTilQ=="], + "gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/swc-win32-x64-msvc@15.4.0-canary.17", "", { "os": "win32", "cpu": "x64" }, "sha512-kEFB4sX2/LM/OpFl08TrV7SIntFJKOh4RfvdUFQ++OTSHDLZz+G24FtRPHx6b6ULWWdNndkY2WfBMH9qy9RfBQ=="], "gitbook-v2/next/postcss": ["postcss@8.4.31", "", { "dependencies": { "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } }, "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ=="], diff --git a/package.json b/package.json index 00f323e2f..8dfd14ef8 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "turbo": "^2.5.0", "vercel": "^39.3.0" }, - "packageManager": "bun@1.2.8", + "packageManager": "bun@1.2.11", "overrides": { "@codemirror/state": "6.4.1", "@gitbook/api": "0.113.0", diff --git a/packages/gitbook-v2/package.json b/packages/gitbook-v2/package.json index 50cf96a0d..a92ed9bad 100644 --- a/packages/gitbook-v2/package.json +++ b/packages/gitbook-v2/package.json @@ -17,7 +17,7 @@ }, "devDependencies": { "gitbook": "*", - "@opennextjs/cloudflare": "^1.0.0-beta.3", + "@opennextjs/cloudflare": "https://pkg.pr.new/opennextjs/opennextjs-cloudflare/@opennextjs/cloudflare@a8815be", "@types/rison": "^0.0.9", "tailwindcss": "^3.4.0", "postcss": "^8" From df9f5a89d424a89bdc74edc424b1ac1e5152dd6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Thu, 1 May 2025 08:40:17 +0200 Subject: [PATCH 2/4] Enable global_fetch_strictly_public --- packages/gitbook-v2/wrangler.jsonc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/gitbook-v2/wrangler.jsonc b/packages/gitbook-v2/wrangler.jsonc index e316e2a24..7fbecf3bc 100644 --- a/packages/gitbook-v2/wrangler.jsonc +++ b/packages/gitbook-v2/wrangler.jsonc @@ -2,7 +2,11 @@ "main": ".open-next/worker.js", "name": "gitbook-open-v2", "compatibility_date": "2025-04-14", - "compatibility_flags": ["nodejs_compat", "allow_importable_env"], + "compatibility_flags": [ + "nodejs_compat", + "allow_importable_env", + "global_fetch_strictly_public" + ], "assets": { "directory": ".open-next/assets", "binding": "ASSETS" From 1e7de51c04681e2b9fbeb3c37b1ce6a8b1811e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Thu, 1 May 2025 08:43:44 +0200 Subject: [PATCH 3/4] Enable withFilter --- packages/gitbook-v2/open-next.config.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/gitbook-v2/open-next.config.ts b/packages/gitbook-v2/open-next.config.ts index 8f4d389da..2ce66f794 100644 --- a/packages/gitbook-v2/open-next.config.ts +++ b/packages/gitbook-v2/open-next.config.ts @@ -3,16 +3,24 @@ import r2IncrementalCache from '@opennextjs/cloudflare/overrides/incremental-cac import { withRegionalCache } from '@opennextjs/cloudflare/overrides/incremental-cache/regional-cache'; import doQueue from '@opennextjs/cloudflare/overrides/queue/do-queue'; import doShardedTagCache from '@opennextjs/cloudflare/overrides/tag-cache/do-sharded-tag-cache'; +import { + softTagFilter, + withFilter, +} from '@opennextjs/cloudflare/overrides/tag-cache/tag-cache-filter'; export default defineCloudflareConfig({ incrementalCache: withRegionalCache(r2IncrementalCache, { mode: 'long-lived' }), - tagCache: doShardedTagCache({ - baseShardSize: 12, - regionalCache: true, - shardReplication: { - numberOfSoftReplicas: 2, - numberOfHardReplicas: 1, - }, + tagCache: withFilter({ + tagCache: doShardedTagCache({ + baseShardSize: 12, + regionalCache: true, + shardReplication: { + numberOfSoftReplicas: 2, + numberOfHardReplicas: 1, + }, + }), + // We don't use `revalidatePath`, so we filter out soft tags + filterFn: softTagFilter, }), queue: doQueue, }); From 8e3895b737de097e24183b21c57c52623b7c37c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Thu, 1 May 2025 09:30:48 +0200 Subject: [PATCH 4/4] Use use cache on cloudflare --- packages/gitbook-v2/src/lib/data/api.ts | 43 +++++++++++------------ packages/gitbook/src/lib/openapi/fetch.ts | 16 ++------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/packages/gitbook-v2/src/lib/data/api.ts b/packages/gitbook-v2/src/lib/data/api.ts index 20e495656..f9cecdf0d 100644 --- a/packages/gitbook-v2/src/lib/data/api.ts +++ b/packages/gitbook-v2/src/lib/data/api.ts @@ -7,12 +7,7 @@ import { type RenderIntegrationUI, } from '@gitbook/api'; import { getCacheTag, getComputedContentSourceCacheTags } from '@gitbook/cache-tags'; -import { - GITBOOK_API_TOKEN, - GITBOOK_API_URL, - GITBOOK_RUNTIME, - GITBOOK_USER_AGENT, -} from '@v2/lib/env'; +import { GITBOOK_API_TOKEN, GITBOOK_API_URL, GITBOOK_USER_AGENT } from '@v2/lib/env'; import { unstable_cacheLife as cacheLife, unstable_cacheTag as cacheTag } from 'next/cache'; import { unstable_cache } from 'next/cache'; import { getCloudflareContext, getCloudflareRequestGlobal } from './cloudflare'; @@ -20,6 +15,8 @@ import { DataFetcherError, wrapDataFetcherError } from './errors'; import { withCacheKey, withoutConcurrentExecution } from './memoize'; import type { GitBookDataFetcher } from './types'; +const withUseCache = true; + interface DataFetcherInput { /** * API token. @@ -221,7 +218,7 @@ const getUserById = withCacheKey( withoutConcurrentExecution( getCloudflareRequestGlobal, async (cacheKey, input: DataFetcherInput, params: { userId: string }) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getUserByIdUseCache(input, params); } @@ -273,7 +270,7 @@ const getSpace = withCacheKey( input: DataFetcherInput, params: { spaceId: string; shareKey: string | undefined } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getSpaceUseCache(input, params); } @@ -345,7 +342,7 @@ const getChangeRequest = withCacheKey( input: DataFetcherInput, params: { spaceId: string; changeRequestId: string } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getChangeRequestUseCache(input, params); } @@ -422,7 +419,7 @@ const getRevision = withCacheKey( input: DataFetcherInput, params: { spaceId: string; revisionId: string; metadata: boolean } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getRevisionUseCache(input, params); } @@ -479,7 +476,7 @@ const getRevisionPages = withCacheKey( input: DataFetcherInput, params: { spaceId: string; revisionId: string; metadata: boolean } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getRevisionPagesUseCache(input, params); } @@ -540,7 +537,7 @@ const getRevisionFile = withCacheKey( input: DataFetcherInput, params: { spaceId: string; revisionId: string; fileId: string } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getRevisionFileUseCache(input, params); } @@ -603,7 +600,7 @@ const getRevisionPageMarkdown = withCacheKey( input: DataFetcherInput, params: { spaceId: string; revisionId: string; pageId: string } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getRevisionPageMarkdownUseCache(input, params); } @@ -673,7 +670,7 @@ const getRevisionPageByPath = withCacheKey( input: DataFetcherInput, params: { spaceId: string; revisionId: string; path: string } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getRevisionPageByPathUseCache(input, params); } @@ -737,7 +734,7 @@ const getDocument = withCacheKey( input: DataFetcherInput, params: { spaceId: string; documentId: string } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getDocumentUseCache(input, params); } @@ -797,7 +794,7 @@ const getComputedDocument = withCacheKey( seed: string; } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getComputedDocumentUseCache(input, params); } @@ -886,7 +883,7 @@ const getReusableContent = withCacheKey( input: DataFetcherInput, params: { spaceId: string; revisionId: string; reusableContentId: string } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getReusableContentUseCache(input, params); } @@ -948,7 +945,7 @@ const getLatestOpenAPISpecVersionContent = withCacheKey( input: DataFetcherInput, params: { organizationId: string; slug: string } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getLatestOpenAPISpecVersionContentUseCache(input, params); } @@ -1025,7 +1022,7 @@ const getPublishedContentSite = withCacheKey( input: DataFetcherInput, params: { organizationId: string; siteId: string; siteShareKey: string | undefined } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getPublishedContentSiteUseCache(input, params); } @@ -1108,7 +1105,7 @@ const getSiteRedirectBySource = withCacheKey( source: string; } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getSiteRedirectBySourceUseCache(input, params); } @@ -1193,7 +1190,7 @@ const getEmbedByUrl = withCacheKey( withoutConcurrentExecution( getCloudflareRequestGlobal, async (cacheKey, input: DataFetcherInput, params: { spaceId: string; url: string }) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return getEmbedByUrlUseCache(input, params); } @@ -1259,7 +1256,7 @@ const searchSiteContent = withCacheKey( input: DataFetcherInput, params: Parameters[0] ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return searchSiteContentUseCache(input, params); } @@ -1330,7 +1327,7 @@ const renderIntegrationUi = withCacheKey( input: DataFetcherInput, params: { integrationName: string; request: RenderIntegrationUI } ) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { + if (withUseCache) { return renderIntegrationUiUseCache(input, params); } diff --git a/packages/gitbook/src/lib/openapi/fetch.ts b/packages/gitbook/src/lib/openapi/fetch.ts index d1f8c03ce..b496bbe59 100644 --- a/packages/gitbook/src/lib/openapi/fetch.ts +++ b/packages/gitbook/src/lib/openapi/fetch.ts @@ -1,5 +1,4 @@ import { parseOpenAPI } from '@gitbook/openapi-parser'; -import { unstable_cache } from 'next/cache'; import { type CacheFunctionOptions, cache, noCacheFetchOptions } from '@/lib/cache'; import type { @@ -10,7 +9,6 @@ import type { } from '@/lib/openapi/types'; import { getCloudflareRequestGlobal } from '@v2/lib/data/cloudflare'; import { withCacheKey, withoutConcurrentExecution } from '@v2/lib/data/memoize'; -import { GITBOOK_RUNTIME } from '@v2/lib/env'; import { assert } from 'ts-essentials'; import { resolveContentRef } from '../references'; import { isV2 } from '../v2'; @@ -71,18 +69,8 @@ const fetchFilesystemV1 = cache({ }); const fetchFilesystemV2 = withCacheKey( - withoutConcurrentExecution(getCloudflareRequestGlobal, async (cacheKey, url: string) => { - if (GITBOOK_RUNTIME !== 'cloudflare') { - return fetchFilesystemUseCache(url); - } - - // FIXME: OpenNext doesn't support 'use cache' yet - const uncached = unstable_cache(async () => fetchFilesystemUncached(url), [cacheKey], { - revalidate: 60 * 60 * 24, - }); - - const response = await uncached(); - return response; + withoutConcurrentExecution(getCloudflareRequestGlobal, async (_cacheKey, url: string) => { + return fetchFilesystemUseCache(url); }) );