Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
c2c42418
Unverified
Commit
c2c42418
authored
Mar 30, 2020
by
Joe Haddad
Committed by
GitHub
Mar 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Lax Cookie for Preview Mode (#11495)
* Use Lax Cookie for Preview Mode * Fix tests
parent
2713369e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
16 deletions
+16
-16
api-utils.ts
packages/next/next-server/server/api-utils.ts
+4
-4
index.test.js
...integration/getserversideprops-preview/test/index.test.js
+6
-6
index.test.js
test/integration/prerender-preview/test/index.test.js
+6
-6
No files found.
packages/next/next-server/server/api-utils.ts
View file @
c2c42418
...
@@ -394,7 +394,7 @@ function setPreviewData<T>(
...
@@ -394,7 +394,7 @@ function setPreviewData<T>(
:
[]),
:
[]),
serialize
(
COOKIE_NAME_PRERENDER_BYPASS
,
options
.
previewModeId
,
{
serialize
(
COOKIE_NAME_PRERENDER_BYPASS
,
options
.
previewModeId
,
{
httpOnly
:
true
,
httpOnly
:
true
,
sameSite
:
'
strict
'
,
sameSite
:
'
lax
'
,
path
:
'/'
,
path
:
'/'
,
...(
options
.
maxAge
!==
undefined
...(
options
.
maxAge
!==
undefined
?
({
maxAge
:
options
.
maxAge
}
as
CookieSerializeOptions
)
?
({
maxAge
:
options
.
maxAge
}
as
CookieSerializeOptions
)
...
@@ -402,7 +402,7 @@ function setPreviewData<T>(
...
@@ -402,7 +402,7 @@ function setPreviewData<T>(
}),
}),
serialize
(
COOKIE_NAME_PRERENDER_DATA
,
payload
,
{
serialize
(
COOKIE_NAME_PRERENDER_DATA
,
payload
,
{
httpOnly
:
true
,
httpOnly
:
true
,
sameSite
:
'
strict
'
,
sameSite
:
'
lax
'
,
path
:
'/'
,
path
:
'/'
,
...(
options
.
maxAge
!==
undefined
...(
options
.
maxAge
!==
undefined
?
({
maxAge
:
options
.
maxAge
}
as
CookieSerializeOptions
)
?
({
maxAge
:
options
.
maxAge
}
as
CookieSerializeOptions
)
...
@@ -431,7 +431,7 @@ function clearPreviewData<T>(res: NextApiResponse<T>): NextApiResponse<T> {
...
@@ -431,7 +431,7 @@ function clearPreviewData<T>(res: NextApiResponse<T>): NextApiResponse<T> {
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
expires
:
new
Date
(
0
),
expires
:
new
Date
(
0
),
httpOnly
:
true
,
httpOnly
:
true
,
sameSite
:
'
strict
'
,
sameSite
:
'
lax
'
,
path
:
'/'
,
path
:
'/'
,
}),
}),
serialize
(
COOKIE_NAME_PRERENDER_DATA
,
''
,
{
serialize
(
COOKIE_NAME_PRERENDER_DATA
,
''
,
{
...
@@ -440,7 +440,7 @@ function clearPreviewData<T>(res: NextApiResponse<T>): NextApiResponse<T> {
...
@@ -440,7 +440,7 @@ function clearPreviewData<T>(res: NextApiResponse<T>): NextApiResponse<T> {
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
expires
:
new
Date
(
0
),
expires
:
new
Date
(
0
),
httpOnly
:
true
,
httpOnly
:
true
,
sameSite
:
'
strict
'
,
sameSite
:
'
lax
'
,
path
:
'/'
,
path
:
'/'
,
}),
}),
])
])
...
...
test/integration/getserversideprops-preview/test/index.test.js
View file @
c2c42418
...
@@ -74,10 +74,10 @@ function runTests(startServer = nextStart) {
...
@@ -74,10 +74,10 @@ function runTests(startServer = nextStart) {
.
map
(
cookie
.
parse
)
.
map
(
cookie
.
parse
)
expect
(
cookies
.
length
).
toBe
(
2
)
expect
(
cookies
.
length
).
toBe
(
2
)
expect
(
cookies
[
0
]).
toMatchObject
({
Path
:
'/'
,
SameSite
:
'
Strict
'
})
expect
(
cookies
[
0
]).
toMatchObject
({
Path
:
'/'
,
SameSite
:
'
Lax
'
})
expect
(
cookies
[
0
]).
toHaveProperty
(
'__prerender_bypass'
)
expect
(
cookies
[
0
]).
toHaveProperty
(
'__prerender_bypass'
)
expect
(
cookies
[
0
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
0
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
1
]).
toMatchObject
({
Path
:
'/'
,
SameSite
:
'
Strict
'
})
expect
(
cookies
[
1
]).
toMatchObject
({
Path
:
'/'
,
SameSite
:
'
Lax
'
})
expect
(
cookies
[
1
]).
toHaveProperty
(
'__next_preview_data'
)
expect
(
cookies
[
1
]).
toHaveProperty
(
'__next_preview_data'
)
expect
(
cookies
[
1
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
1
]).
not
.
toHaveProperty
(
'Max-Age'
)
...
@@ -135,21 +135,21 @@ function runTests(startServer = nextStart) {
...
@@ -135,21 +135,21 @@ function runTests(startServer = nextStart) {
const
cookies
=
res
.
headers
const
cookies
=
res
.
headers
.
get
(
'set-cookie'
)
.
get
(
'set-cookie'
)
.
replace
(
/
(
=
\w{3})
,/g
,
'$1'
)
.
replace
(
/
(
=
(?!
Lax
)
\w{3})
,/g
,
'$1'
)
.
split
(
','
)
.
split
(
','
)
.
map
(
cookie
.
parse
)
.
map
(
cookie
.
parse
)
expect
(
cookies
.
length
).
toBe
(
2
)
expect
(
cookies
.
length
).
toBe
(
2
)
expect
(
cookies
[
0
]).
toMatchObject
({
expect
(
cookies
[
0
]).
toMatchObject
({
Path
:
'/'
,
Path
:
'/'
,
SameSite
:
'
Strict
'
,
SameSite
:
'
Lax
'
,
Expires
:
'Thu 01 Jan 1970 00:00:00 GMT'
,
Expires
:
'Thu 01 Jan 1970 00:00:00 GMT'
,
})
})
expect
(
cookies
[
0
]).
toHaveProperty
(
'__prerender_bypass'
)
expect
(
cookies
[
0
]).
toHaveProperty
(
'__prerender_bypass'
)
expect
(
cookies
[
0
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
0
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
1
]).
toMatchObject
({
expect
(
cookies
[
1
]).
toMatchObject
({
Path
:
'/'
,
Path
:
'/'
,
SameSite
:
'
Strict
'
,
SameSite
:
'
Lax
'
,
Expires
:
'Thu 01 Jan 1970 00:00:00 GMT'
,
Expires
:
'Thu 01 Jan 1970 00:00:00 GMT'
,
})
})
expect
(
cookies
[
1
]).
toHaveProperty
(
'__next_preview_data'
)
expect
(
cookies
[
1
]).
toHaveProperty
(
'__next_preview_data'
)
...
@@ -266,7 +266,7 @@ describe('ServerSide Props Preview Mode', () => {
...
@@ -266,7 +266,7 @@ describe('ServerSide Props Preview Mode', () => {
const
cookies
=
res
.
headers
const
cookies
=
res
.
headers
.
get
(
'set-cookie'
)
.
get
(
'set-cookie'
)
.
replace
(
/
(
=
\w{3})
,/g
,
'$1'
)
.
replace
(
/
(
=
(?!
Lax
)
\w{3})
,/g
,
'$1'
)
.
split
(
','
)
.
split
(
','
)
.
map
(
cookie
.
parse
)
.
map
(
cookie
.
parse
)
...
...
test/integration/prerender-preview/test/index.test.js
View file @
c2c42418
...
@@ -80,10 +80,10 @@ function runTests(startServer = nextStart) {
...
@@ -80,10 +80,10 @@ function runTests(startServer = nextStart) {
.
map
(
cookie
.
parse
)
.
map
(
cookie
.
parse
)
expect
(
cookies
.
length
).
toBe
(
2
)
expect
(
cookies
.
length
).
toBe
(
2
)
expect
(
cookies
[
0
]).
toMatchObject
({
Path
:
'/'
,
SameSite
:
'
Strict
'
})
expect
(
cookies
[
0
]).
toMatchObject
({
Path
:
'/'
,
SameSite
:
'
Lax
'
})
expect
(
cookies
[
0
]).
toHaveProperty
(
'__prerender_bypass'
)
expect
(
cookies
[
0
]).
toHaveProperty
(
'__prerender_bypass'
)
expect
(
cookies
[
0
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
0
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
1
]).
toMatchObject
({
Path
:
'/'
,
SameSite
:
'
Strict
'
})
expect
(
cookies
[
1
]).
toMatchObject
({
Path
:
'/'
,
SameSite
:
'
Lax
'
})
expect
(
cookies
[
1
]).
toHaveProperty
(
'__next_preview_data'
)
expect
(
cookies
[
1
]).
toHaveProperty
(
'__next_preview_data'
)
expect
(
cookies
[
1
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
1
]).
not
.
toHaveProperty
(
'Max-Age'
)
...
@@ -141,21 +141,21 @@ function runTests(startServer = nextStart) {
...
@@ -141,21 +141,21 @@ function runTests(startServer = nextStart) {
const
cookies
=
res
.
headers
const
cookies
=
res
.
headers
.
get
(
'set-cookie'
)
.
get
(
'set-cookie'
)
.
replace
(
/
(
=
\w{3})
,/g
,
'$1'
)
.
replace
(
/
(
=
(?!
Lax
)
\w{3})
,/g
,
'$1'
)
.
split
(
','
)
.
split
(
','
)
.
map
(
cookie
.
parse
)
.
map
(
cookie
.
parse
)
expect
(
cookies
.
length
).
toBe
(
2
)
expect
(
cookies
.
length
).
toBe
(
2
)
expect
(
cookies
[
0
]).
toMatchObject
({
expect
(
cookies
[
0
]).
toMatchObject
({
Path
:
'/'
,
Path
:
'/'
,
SameSite
:
'
Strict
'
,
SameSite
:
'
Lax
'
,
Expires
:
'Thu 01 Jan 1970 00:00:00 GMT'
,
Expires
:
'Thu 01 Jan 1970 00:00:00 GMT'
,
})
})
expect
(
cookies
[
0
]).
toHaveProperty
(
'__prerender_bypass'
)
expect
(
cookies
[
0
]).
toHaveProperty
(
'__prerender_bypass'
)
expect
(
cookies
[
0
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
0
]).
not
.
toHaveProperty
(
'Max-Age'
)
expect
(
cookies
[
1
]).
toMatchObject
({
expect
(
cookies
[
1
]).
toMatchObject
({
Path
:
'/'
,
Path
:
'/'
,
SameSite
:
'
Strict
'
,
SameSite
:
'
Lax
'
,
Expires
:
'Thu 01 Jan 1970 00:00:00 GMT'
,
Expires
:
'Thu 01 Jan 1970 00:00:00 GMT'
,
})
})
expect
(
cookies
[
1
]).
toHaveProperty
(
'__next_preview_data'
)
expect
(
cookies
[
1
]).
toHaveProperty
(
'__next_preview_data'
)
...
@@ -266,7 +266,7 @@ describe('Prerender Preview Mode', () => {
...
@@ -266,7 +266,7 @@ describe('Prerender Preview Mode', () => {
const
cookies
=
res
.
headers
const
cookies
=
res
.
headers
.
get
(
'set-cookie'
)
.
get
(
'set-cookie'
)
.
replace
(
/
(
=
\w{3})
,/g
,
'$1'
)
.
replace
(
/
(
=
(?!
Lax
)
\w{3})
,/g
,
'$1'
)
.
split
(
','
)
.
split
(
','
)
.
map
(
cookie
.
parse
)
.
map
(
cookie
.
parse
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment