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
0ecde6bd
Unverified
Commit
0ecde6bd
authored
Aug 03, 2023
by
Shu Ding
Committed by
GitHub
Aug 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for client router state invalidation caused by cookie mutations (#53494)
Closes #53261. Closes NEXT-1478.
parent
3c84b3ac
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
1 deletion
+66
-1
app-action.test.ts
test/e2e/app-dir/actions/app-action.test.ts
+30
-1
page.js
test/e2e/app-dir/actions/app/mutate-cookie/page-2/page.js
+13
-0
page.js
test/e2e/app-dir/actions/app/mutate-cookie/page.js
+23
-0
No files found.
test/e2e/app-dir/actions/app-action.test.ts
View file @
0ecde6bd
...
@@ -533,7 +533,6 @@ createNextDescribe(
...
@@ -533,7 +533,6 @@ createNextDescribe(
expect
(
newJustPutIt
).
toEqual
(
newJustPutIt2
)
expect
(
newJustPutIt
).
toEqual
(
newJustPutIt2
)
})
})
// TODO: investigate flakey behavior with revalidate
it
(
'should revalidate when cookies.set is called'
,
async
()
=>
{
it
(
'should revalidate when cookies.set is called'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/revalidate'
)
const
browser
=
await
next
.
browser
(
'/revalidate'
)
const
randomNumber
=
await
browser
.
elementByCss
(
'#random-cookie'
).
text
()
const
randomNumber
=
await
browser
.
elementByCss
(
'#random-cookie'
).
text
()
...
@@ -549,6 +548,36 @@ createNextDescribe(
...
@@ -549,6 +548,36 @@ createNextDescribe(
},
'success'
)
},
'success'
)
})
})
it
(
'should invalidate client cache on other routes when cookies.set is called'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/mutate-cookie'
)
await
browser
.
elementByCss
(
'#update-cookie'
).
click
()
let
cookie
await
check
(
async
()
=>
{
cookie
=
await
browser
.
elementByCss
(
'#value'
).
text
()
return
parseInt
(
cookie
)
>
0
?
'success'
:
'failure'
},
'success'
)
// Make sure the route is cached
await
browser
.
elementByCss
(
'#page-2'
).
click
()
await
browser
.
elementByCss
(
'#back'
).
click
()
// Modify the cookie
await
browser
.
elementByCss
(
'#update-cookie'
).
click
()
let
newCookie
await
check
(
async
()
=>
{
newCookie
=
await
browser
.
elementByCss
(
'#value'
).
text
()
return
newCookie
!==
cookie
&&
parseInt
(
newCookie
)
>
0
?
'success'
:
'failure'
},
'success'
)
// Navigate to another page and make sure the cookie is not cached
await
browser
.
elementByCss
(
'#page-2'
).
click
()
const
otherPageCookie
=
await
browser
.
elementByCss
(
'#value'
).
text
()
expect
(
otherPageCookie
).
toEqual
(
newCookie
)
})
// TODO: investigate flakey behavior with revalidate
// TODO: investigate flakey behavior with revalidate
it
(
'should revalidate when cookies.set is called in a client action'
,
async
()
=>
{
it
(
'should revalidate when cookies.set is called in a client action'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/revalidate'
)
const
browser
=
await
next
.
browser
(
'/revalidate'
)
...
...
test/e2e/app-dir/actions/app/mutate-cookie/page-2/page.js
0 → 100644
View file @
0ecde6bd
import
{
cookies
}
from
'next/headers'
import
Link
from
'next/link'
export
default
function
Page
()
{
return
(
<>
<
Link
id
=
"back"
href
=
"/mutate-cookie"
>
back
<
/Link
>
<
p
id
=
"value"
>
{
cookies
().
get
(
'test-cookie2'
)?.
value
}
<
/p
>
<
/
>
)
}
test/e2e/app-dir/actions/app/mutate-cookie/page.js
0 → 100644
View file @
0ecde6bd
import
{
cookies
}
from
'next/headers'
import
Link
from
'next/link'
async
function
updateCookie
()
{
'use server'
cookies
().
set
(
'test-cookie2'
,
Date
.
now
())
}
export
default
function
Page
()
{
return
(
<>
<
Link
id
=
"page-2"
href
=
"/mutate-cookie/page-2"
>
to
page2
<
/Link
>
<
p
id
=
"value"
>
{
cookies
().
get
(
'test-cookie2'
)?.
value
}
<
/p
>
<
form
action
=
{
updateCookie
}
>
<
button
id
=
"update-cookie"
type
=
"submit"
>
Update
Cookie
<
/button
>
<
/form
>
<
/
>
)
}
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