Skip to content

Commit 7829266

Browse files
committed
Refactor edge-config to prepare for Next.js support
This change refactors the edge-config implementation in preparation for supporting Next.js specific builds. The key goal is to prepare the function interfaces where we intend to push the "use cache" boundaries for Next.js support so they are stringly typed. This is to help with optimizing a fast path for "use cache" that can avoid some serialization. One concession in this refactor is we need to move from a closure for the dev-only SWR edge config fetcher. The problem with this architecture is the function created in the closure won't be accessible to the the individual methods (like get) when they are behind a "use cache" because functions are not serializable. The technique now employed is a lazy created SWR deduper that is keyed off the connection string. This implementation does not consider garbage collection when clients are collected because 1) this is dev only and dev servers don't live very long and 2) this library does not typically require creating arbitrarily many clients since connections are typically stable for the lifetime of a deployment. We could use a FinalizationRegistry but that would limit support to runtimes that provide this and require some careful conditional requiring which just adds bundling complexity.
1 parent 1d471f6 commit 7829266

File tree

10 files changed

+1692
-457
lines changed

10 files changed

+1692
-457
lines changed

packages/edge-config/src/index copy.ts

Lines changed: 615 additions & 0 deletions
Large diffs are not rendered by default.

packages/edge-config/src/index.ts

Lines changed: 114 additions & 381 deletions
Large diffs are not rendered by default.

packages/edge-config/src/methods.ts

Lines changed: 471 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "tsconfig/base.json",
3+
"compilerOptions": {
4+
"resolveJsonModule": true
5+
},
6+
"include": ["src"]
7+
}

packages/edge-config/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"extends": "tsconfig/base.json",
33
"compilerOptions": {
4-
"resolveJsonModule": true
4+
"resolveJsonModule": true,
5+
"paths": {
6+
"@vercel/edge-config/host-config": [
7+
"./src/host-config/default.ts",
8+
"./src/host-config/next-js.ts"
9+
]
10+
}
511
},
612
"include": ["src"]
713
}
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { defineConfig } from 'tsup';
22

33
// eslint-disable-next-line import/no-default-export -- [@vercel/style-guide@5 migration]
4-
export default defineConfig({
5-
entry: ['src/index.ts'],
6-
format: ['esm', 'cjs'],
7-
splitting: true,
8-
sourcemap: true,
9-
minify: false,
10-
clean: true,
11-
skipNodeModulesBundle: true,
12-
dts: true,
13-
external: ['node_modules'],
14-
});
4+
export default [
5+
defineConfig({
6+
entry: ['src/index.ts'],
7+
format: ['esm', 'cjs'],
8+
splitting: true,
9+
sourcemap: true,
10+
minify: false,
11+
clean: true,
12+
skipNodeModulesBundle: true,
13+
dts: true,
14+
external: ['node_modules'],
15+
}),
16+
];

pnpm-lock.yaml

Lines changed: 462 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/next/.vscode/settings.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"got": "^14.4.6",
2929
"kysely": "^0.27.5",
3030
"ms": "^2.1.3",
31-
"next": "^15.2.0",
31+
"next": "15.2.5",
3232
"postcss": "^8.5.3",
3333
"react": "^19.0.0",
3434
"react-dom": "^19.0.0",

test/next/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"**/*.ts",
3030
"**/*.tsx",
3131
".next/types/**/*.ts",
32-
"src/app/vercel/blob/script.mts"
32+
"src/app/vercel/blob/script.mts",
33+
".next/dev/types/**/*.ts"
3334
],
3435
"exclude": ["node_modules"]
3536
}

0 commit comments

Comments
 (0)