-
Notifications
You must be signed in to change notification settings - Fork 176
Fix remove prefetch header for Next 14.1+ #825
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e147428
patch to disable background revalidation
conico974 057a8de
remove prefetch header from request
conico974 2eba6c1
changeset
conico974 e7902b1
lint
conico974 53edd4f
Update packages/tests-unit/tests/build/patch/patches/patchBackgroundR…
conico974 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@opennextjs/aws": patch | ||
--- | ||
|
||
remove prefetch header for next 14.1+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/open-next/src/build/patch/patches/patchBackgroundRevalidation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getCrossPlatformPathRegex } from "utils/regex.js"; | ||
import { createPatchCode } from "../astCodePatcher.js"; | ||
import type { CodePatcher } from "../codePatcher.js"; | ||
|
||
export const rule = ` | ||
rule: | ||
kind: binary_expression | ||
all: | ||
- has: | ||
kind: unary_expression | ||
regex: "!cachedResponse.isStale" | ||
- has: | ||
kind: member_expression | ||
regex: "context.isPrefetch" | ||
fix: | ||
'true'`; | ||
|
||
export const patchBackgroundRevalidation = { | ||
name: "patchBackgroundRevalidation", | ||
patches: [ | ||
{ | ||
// TODO: test for earlier versions of Next | ||
versions: ">=14.1.0", | ||
field: { | ||
pathFilter: getCrossPlatformPathRegex("server/response-cache/index.js"), | ||
patchCode: createPatchCode(rule), | ||
}, | ||
}, | ||
], | ||
} satisfies CodePatcher; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/tests-unit/tests/build/patch/patches/patchBackgroundRevalidation.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js"; | ||
import { rule } from "@opennextjs/aws/build/patch/patches/patchBackgroundRevalidation.js"; | ||
import { describe, it } from "vitest"; | ||
|
||
const codeToPatch = `if (cachedResponse && !isOnDemandRevalidate) { | ||
var _cachedResponse_value; | ||
if (((_cachedResponse_value = cachedResponse.value) == null ? void 0 : _cachedResponse_value.kind) === _types.CachedRouteKind.FETCH) { | ||
throw new Error(\`invariant: unexpected cachedResponse of kind fetch in response cache\`); | ||
} | ||
resolve({ | ||
...cachedResponse, | ||
revalidate: cachedResponse.curRevalidate | ||
}); | ||
resolved = true; | ||
if (!cachedResponse.isStale || context.isPrefetch) { | ||
// The cached value is still valid, so we don't need | ||
// to update it yet. | ||
return null; | ||
} | ||
}`; | ||
|
||
describe("patchBackgroundRevalidation", () => { | ||
it("Should patch code for Next 14+", () => { | ||
expect( | ||
patchCode(codeToPatch, rule), | ||
).toMatchInlineSnapshot(`"if (cachedResponse && !isOnDemandRevalidate) { | ||
var _cachedResponse_value; | ||
if (((_cachedResponse_value = cachedResponse.value) == null ? void 0 : _cachedResponse_value.kind) === _types.CachedRouteKind.FETCH) { | ||
throw new Error(\`invariant: unexpected cachedResponse of kind fetch in response cache\`); | ||
} | ||
resolve({ | ||
...cachedResponse, | ||
revalidate: cachedResponse.curRevalidate | ||
}); | ||
resolved = true; | ||
if (true) { | ||
// The cached value is still valid, so we don't need | ||
// to update it yet. | ||
return null; | ||
} | ||
}"`); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.