mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 12:57:47 +00:00
[build-utils] add experimentalBypassFor field to Prerender (#10481)
This adds an experimental flag to `Prerender` outputs as a way to programmatically bypass the cache and hit the lambda directly, using a similar interface to `has`. (Note: I copied over `HasField` from `@vercel/router-utils` since it wasn't available for import in `build-utils`, but can add it as a dep if that's preferred) The specific use-case being targeted here relates to https://github.com/vercel/next.js/pull/51534 -- a Next.js page marked static should still be able to initiate server actions.
This commit is contained in:
64
packages/build-utils/test/unit.test.ts
vendored
64
packages/build-utils/test/unit.test.ts
vendored
@@ -344,6 +344,70 @@ it('should support initialHeaders and initialStatus correctly', async () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support experimentalBypassFor correctly', async () => {
|
||||
new Prerender({
|
||||
expiration: 1,
|
||||
fallback: null,
|
||||
group: 1,
|
||||
bypassToken: 'some-long-bypass-token-to-make-it-work',
|
||||
experimentalBypassFor: [{ type: 'header', key: 'Next-Action' }],
|
||||
});
|
||||
new Prerender({
|
||||
expiration: 1,
|
||||
fallback: null,
|
||||
group: 1,
|
||||
bypassToken: 'some-long-bypass-token-to-make-it-work',
|
||||
experimentalBypassFor: [
|
||||
{ type: 'header', key: 'Next-Action' },
|
||||
{
|
||||
type: 'cookie',
|
||||
key: '__prerender_bypass',
|
||||
value: 'some-long-bypass-token-to-make-it-work',
|
||||
},
|
||||
],
|
||||
});
|
||||
new Prerender({
|
||||
expiration: 1,
|
||||
fallback: null,
|
||||
group: 1,
|
||||
bypassToken: 'some-long-bypass-token-to-make-it-work',
|
||||
experimentalBypassFor: [{ type: 'query', key: 'bypass', value: '1' }],
|
||||
});
|
||||
new Prerender({
|
||||
expiration: 1,
|
||||
fallback: null,
|
||||
group: 1,
|
||||
bypassToken: 'some-long-bypass-token-to-make-it-work',
|
||||
experimentalBypassFor: [{ type: 'host', value: 'vercel.com' }],
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
new Prerender({
|
||||
expiration: 1,
|
||||
fallback: null,
|
||||
group: 1,
|
||||
bypassToken: 'some-long-bypass-token-to-make-it-work',
|
||||
// @ts-expect-error: testing invalid args
|
||||
experimentalBypassFor: 'foo',
|
||||
});
|
||||
}).toThrowError(
|
||||
'The `experimentalBypassFor` argument for `Prerender` must be Array of objects with fields `type`, `key` and optionally `value`.'
|
||||
);
|
||||
|
||||
expect(() => {
|
||||
new Prerender({
|
||||
expiration: 1,
|
||||
fallback: null,
|
||||
group: 1,
|
||||
bypassToken: 'some-long-bypass-token-to-make-it-work',
|
||||
// @ts-expect-error: testing invalid args
|
||||
experimentalBypassFor: [{ type: 'header', value: { foo: 'bar' } }],
|
||||
});
|
||||
}).toThrowError(
|
||||
'The `experimentalBypassFor` argument for `Prerender` must be Array of objects with fields `type`, `key` and optionally `value`.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should support passQuery correctly', async () => {
|
||||
new Prerender({
|
||||
expiration: 1,
|
||||
|
||||
Reference in New Issue
Block a user