Skip to content

Commit

Permalink
fix ISR when used in addition to middleware rewrite (#143)
Browse files Browse the repository at this point in the history
* hash MessageDeduplicationId to avoid invalid values

* Sync

* added middleware rewrite with ISR

* fix: make isr work with middleware rewrite

* remove unecessary changes

* add some usefull comments

* Sync

---------

Co-authored-by: Frank <[email protected]>
  • Loading branch information
mathisobadia and fwang committed Jun 27, 2023
1 parent 22e8f70 commit d6db51f
Show file tree
Hide file tree
Showing 8 changed files with 1,986 additions and 969 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-drinks-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"open-next": patch
---

revalidation: fix ISR revalidation for rewritten URL
6 changes: 6 additions & 0 deletions example/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export async function middleware(request) {
url.searchParams.set("rewritten", "true")
return NextResponse.rewrite(url);
}
if (request.nextUrl.pathname === "/middleware-rewrite-with-isr") {
const { nextUrl: url } = request
url.pathname = `/middleware-rewrite-with-isr-destination`
return NextResponse.rewrite(url)
}
if (request.nextUrl.pathname === "/middleware-redirect") {
return NextResponse.redirect(new URL("/middleware-redirect-destination", request.url));
}
Expand Down Expand Up @@ -49,6 +54,7 @@ export async function middleware(request) {
export const config = {
matcher: [
"/middleware-rewrite",
"/middleware-rewrite-with-isr",
"/middleware-redirect",
"/middleware-set-header",
"/middleware-fetch",
Expand Down
13 changes: 7 additions & 6 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
"scripts": {
"dev": "sst bind next dev",
"build": "next build",
"start": "next start"
"start": "next start",
"deploy": "sst deploy"
},
"dependencies": {
"@next/font": "13.0.5",
"@next/font": "13.4.7",
"date-fns": "^2.23.0",
"gray-matter": "^4.0.3",
"next": "13.0.5",
"next-auth": "^4.22.0",
"next": "13.4.7",
"next-auth": "^4.22.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"remark": "^13.0.0",
"remark-html": "^13.0.2",
"swr": "^1.0.1"
},
"devDependencies": {
"aws-cdk-lib": "2.72.1",
"aws-cdk-lib": "2.84.0",
"constructs": "10.1.156",
"sst": "^2.5.3"
"sst": "2.16.3"
}
}
3 changes: 1 addition & 2 deletions example/pages/middleware-redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export default function Page() {
</h1>
<hr />
<p>
<b>Test 1:</b>
If you see this page, Middleware with redirect is NOT working. You should be redirected to /middleware-redirect-destination.
❌ If you see this page, Middleware with redirect is NOT working. You should be redirected to /middleware-redirect-destination.
</p>
</article>
</Layout>
Expand Down
27 changes: 27 additions & 0 deletions example/pages/middleware-rewrite-with-isr-destination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Layout from "../components/layout";

export async function getStaticProps() {
return {
props: {
time: Date.now(),
},
revalidate: 10,
};
}

export default function Page({ time }) {
return (
<Layout>
<article>
<h1>
Middleware — rewrite with Incremental Static Rendering (ISR)
</h1>
<hr />
<p>
<b>Test 1:</b>
This timestamp 👉 {time} should change every 10 seconds when the page is repeatedly refreshed.
</p>
</article>
</Layout>
);
}
17 changes: 17 additions & 0 deletions example/pages/middleware-rewrite-with-isr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Layout from "../components/layout";

export default function Page() {
return (
<Layout>
<article>
<h1>
Middleware — rewrite with Incremental Static Rendering (ISR)
</h1>
<hr />
<p>
❌ If you see this page, Middleware with rewrite is NOT working.
</p>
</article>
</Layout>
);
}
Loading

1 comment on commit d6db51f

@vercel
Copy link

@vercel vercel bot commented on d6db51f Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

open-next – ./

open-next-sst-dev.vercel.app
open-next-git-main-sst-dev.vercel.app
open-next.vercel.app

Please sign in to comment.