mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
4aa7663084
* fix(app-router): hard navigate stale RSC build payloads App Router soft navigation currently accepts any valid RSC payload after deploy. That lets stale tabs decode RSC responses produced by a different build, which can break client navigation when the server and browser artifacts no longer match. The missing invariant was that every RSC response consumed by the browser must identify the build that produced it, and the browser must reject payloads from a different build before handing them to React. Emit a vinext-owned build ID header on App Router RSC responses, preserve it in prefetched and visited response snapshots, and hard navigate when a response is missing or mismatches the current client build ID. * chore: fix e2e fixture hook lint suppression * chore: avoid hook-like fixture callback name * fix(app-router): preserve build IDs for cached RSC payloads * fix(app-router): use public RSC compatibility IDs
39 lines
834 B
TypeScript
39 lines
834 B
TypeScript
export function withEnvVar<T>(
|
|
name: string,
|
|
value: string | undefined,
|
|
run: () => Promise<T>,
|
|
): Promise<T>;
|
|
export function withEnvVar<T>(name: string, value: string | undefined, run: () => T): T;
|
|
export function withEnvVar<T>(
|
|
name: string,
|
|
value: string | undefined,
|
|
run: () => T | Promise<T>,
|
|
): T | Promise<T> {
|
|
const previous = process.env[name];
|
|
if (value === undefined) {
|
|
delete process.env[name];
|
|
} else {
|
|
process.env[name] = value;
|
|
}
|
|
|
|
const restore = () => {
|
|
if (previous === undefined) {
|
|
delete process.env[name];
|
|
} else {
|
|
process.env[name] = previous;
|
|
}
|
|
};
|
|
|
|
try {
|
|
const result = run();
|
|
if (result instanceof Promise) {
|
|
return result.finally(restore);
|
|
}
|
|
restore();
|
|
return result;
|
|
} catch (error) {
|
|
restore();
|
|
throw error;
|
|
}
|
|
}
|