Skip to content

Commit 577630f

Browse files
authored
Merge branch 'main' into no-bundler-for-nothing
2 parents 6d3668c + 6b527be commit 577630f

File tree

27 files changed

+1920
-212
lines changed

27 files changed

+1920
-212
lines changed

.github/workflows/add-to-project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
steps:
1010
- name: Generate token
1111
id: generate_token
12-
uses: tibdex/github-app-token@v1.5.2
12+
uses: tibdex/github-app-token@v1.8.0
1313
with:
1414
app_id: ${{ secrets.TOKENS_APP_ID }}
1515
private_key: ${{ secrets.TOKENS_PRIVATE_KEY }}

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.20.0
1+
16.20.1

.release-please-manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"packages/runtime": "4.38.0",
3-
"packages/next": "1.4.7"
2+
"packages/runtime": "4.38.1",
3+
"packages/next": "1.4.8"
44
}

cypress/e2e/middleware/enhanced.cy.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
describe('Enhanced middleware', () => {
2-
it('rewrites the response body', () => {
2+
it('rewrites the response body using request.rewrite()', () => {
3+
cy.visit('/request-rewrite')
4+
cy.get('#message').contains('This was static (& escaping test &) but has been transformed in')
5+
cy.contains("This is an ad that isn't shown by default")
6+
})
7+
8+
it('modifies the page props when using request.rewrite()', () => {
9+
cy.visit('/request-rewrite')
10+
cy.get('script#__NEXT_DATA__').then((element) => {
11+
const { props } = JSON.parse(element.text());
12+
expect(props.pageProps.message).to.include('This was static (& escaping test &) but has been transformed in')
13+
})
14+
})
15+
16+
it('passes in headers within request.rewrite()', () => {
17+
cy.request('/request-rewrite').then((response) => {
18+
expect(response.headers).to.have.property('x-rewrite-test', 'hello')
19+
})
20+
})
21+
22+
it('rewrites the response body using request.next()', () => {
323
cy.visit('/static')
424
cy.get('#message').contains('This was static (& escaping test &) but has been transformed in')
525
cy.contains("This is an ad that isn't shown by default")

cypress/e2e/middleware/standard.cy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ describe('Standard middleware', () => {
4545
expect(response.headers).to.have.property('x-foo', 'bar')
4646
})
4747
})
48+
49+
it('preserves locale on rewrites (skipMiddlewareUrlNormalize: true)', () => {
50+
cy.visit('/de-de/locale-preserving-rewrite')
51+
cy.get('div').should('contain', 'Locale: de-DE')
52+
cy.url().should('eq', `${Cypress.config().baseUrl}/de-de/locale-preserving-rewrite`)
53+
})
4854
})
4955

5056
describe('Middleware matchers', () => {

demos/middleware/middleware.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,37 @@ export async function middleware(req: NextRequest) {
2121
}
2222

2323
const request = new MiddlewareRequest(req)
24-
if (pathname.startsWith('/static')) {
24+
25+
// skipMiddlewareUrlNormalize next config option is used so we have to try to match both html path and data blob path
26+
if (pathname.startsWith('/static') || pathname.endsWith('/static.json')) {
2527
// Unlike NextResponse.next(), this actually sends the request to the origin
2628
const res = await request.next()
2729
const message = `This was static (& escaping test &) but has been transformed in ${req.geo?.city}`
2830

2931
// Transform the response HTML and props
30-
res.replaceText('p[id=message]', message)
32+
res.replaceText('#message', message)
33+
res.setPageProp('message', message)
34+
res.setPageProp('showAd', true)
35+
36+
res.headers.set('x-modified-edge', 'true')
37+
res.headers.set('x-is-deno', 'Deno' in globalThis ? 'true' : 'false')
38+
return res
39+
}
40+
41+
// skipMiddlewareUrlNormalize next config option is used so we have to try to match both html path and data blob path
42+
if (pathname.startsWith('/request-rewrite') || pathname.endsWith('/request-rewrite.json')) {
43+
// request.rewrite() should return the MiddlewareResponse object instead of the Response object.
44+
const res = await request.rewrite('/static-rewrite',
45+
{
46+
headers: {
47+
'x-rewrite-test': 'hello',
48+
'x-rewrite-test-2': 'hello-2'
49+
}
50+
})
51+
const message = `This was static (& escaping test &) but has been transformed in ${req.geo?.city}`
52+
53+
// Transform the response HTML and props
54+
res.replaceText('#message', message)
3155
res.setPageProp('message', message)
3256
res.setPageProp('showAd', true)
3357

@@ -85,6 +109,10 @@ export async function middleware(req: NextRequest) {
85109
return response
86110
}
87111

112+
if (pathname.includes('locale-preserving-rewrite')) {
113+
return NextResponse.rewrite(new URL('/locale-test', req.url))
114+
}
115+
88116
if (pathname.startsWith('/shows')) {
89117
if (pathname.startsWith('/shows/222')) {
90118
response = NextResponse.next()
@@ -136,8 +164,10 @@ export const config = {
136164
matcher: [
137165
'/api/:all*',
138166
'/headers',
167+
'/:all*/locale-preserving-rewrite',
139168
'/cookies/:path*',
140169
{ source: '/static' },
170+
{source: '/request-rewrite' },
141171
{ source: '/matcher-cookie'},
142172
{ source: '/shows/((?!99|88).*)' },
143173
{

demos/middleware/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const nextConfig = {
1111
defaultLocale: 'en',
1212
locales: ['en', 'de-DE'],
1313
},
14+
skipMiddlewareUrlNormalize: true,
1415
}
1516

1617
module.exports = nextConfig

demos/middleware/pages/locale-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react'
2+
3+
const Page = ({ pageLocale }) => {
4+
return <div>Locale: {pageLocale}</div>
5+
}
6+
7+
export async function getServerSideProps({ locale }) {
8+
return {
9+
props: {
10+
pageLocale: locale,
11+
},
12+
}
13+
}
14+
15+
export default Page
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const Rewrite = () => {
2+
return (
3+
<div>
4+
<p>This should have been rewritten</p>
5+
</div>
6+
)
7+
}
8+
9+
export default Rewrite
10+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as React from 'react'
2+
3+
const useHydrated = () => {
4+
const [hydrated, setHydrated] = React.useState(false)
5+
React.useEffect(() => {
6+
setHydrated(true)
7+
}, [])
8+
return hydrated
9+
}
10+
11+
const Page = ({ message, showAd }) => {
12+
const hydrated = useHydrated()
13+
return (
14+
<div>
15+
<p id="message">{message}</p>
16+
{hydrated && showAd ? (
17+
<div>
18+
<p>This is an ad that isn't shown by default on static test 2 page</p>
19+
<img src="http://placekitten.com/400/300" />
20+
</div>
21+
) : (
22+
<p>No ads for me</p>
23+
)}
24+
</div>
25+
)
26+
}
27+
28+
export async function getStaticProps() {
29+
return {
30+
props: {
31+
message: 'This is a static page',
32+
showAd: false,
33+
},
34+
}
35+
}
36+
37+
export default Page

demos/nx-next-monorepo-demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"@testing-library/react": "13.4.0",
3131
"@types/jest": "28.1.8",
3232
"@types/node": "16.18.36",
33-
"@types/react": "18.0.38",
34-
"@types/react-dom": "18.0.11",
33+
"@types/react": "18.2.14",
34+
"@types/react-dom": "18.2.6",
3535
"@typescript-eslint/eslint-plugin": "^5.36.1",
3636
"@typescript-eslint/parser": "^5.36.1",
3737
"babel-jest": "28.1.3",

demos/turborepo-next-monorepo-demo/apps/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"devDependencies": {
1818
"@babel/core": "^7.0.0",
1919
"@types/node": "^17.0.12",
20-
"@types/react": "18.0.38",
20+
"@types/react": "18.2.14",
2121
"eslint": "7.32.0",
2222
"eslint-config-custom": "*",
2323
"next-transpile-modules": "9.0.0",

demos/turborepo-next-monorepo-demo/apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"devDependencies": {
1818
"@babel/core": "^7.0.0",
1919
"@types/node": "^17.0.12",
20-
"@types/react": "18.0.38",
20+
"@types/react": "18.2.14",
2121
"eslint": "7.32.0",
2222
"eslint-config-custom": "*",
2323
"next-transpile-modules": "9.0.0",

demos/turborepo-next-monorepo-demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
"react": "^18.2.0",
2828
"react-dom": "^18.2.0"
2929
},
30-
"packageManager": "npm@8.11.0"
30+
"packageManager": "npm@8.19.4"
3131
}

0 commit comments

Comments
 (0)