-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add a case for not awaited res.revalidate
- Loading branch information
Showing
3 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
12 changes: 12 additions & 0 deletions
12
tests/fixtures/page-router-base-path-i18n/pages/api/revalidate-no-await.js
This file contains 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,12 @@ | ||
export default async function handler(req, res) { | ||
try { | ||
const pathToPurge = req.query.path ?? '/static/revalidate-manual' | ||
// res.revalidate returns a promise that can be awaited to wait for the revalidation to complete | ||
// if user doesn't await it, we still want to ensure the revalidation is completed, so we internally track | ||
// this as "background work" to ensure it completes before function suspends execution | ||
res.revalidate(pathToPurge) | ||
return res.json({ code: 200, message: 'success' }) | ||
} catch (err) { | ||
return res.status(500).send({ code: 500, message: err.message }) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/fixtures/page-router/pages/api/revalidate-no-await.js
This file contains 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,12 @@ | ||
export default async function handler(req, res) { | ||
try { | ||
const pathToPurge = req.query.path ?? '/static/revalidate-manual' | ||
// res.revalidate returns a promise that can be awaited to wait for the revalidation to complete | ||
// if user doesn't await it, we still want to ensure the revalidation is completed, so we internally track | ||
// this as "background work" to ensure it completes before function suspends execution | ||
res.revalidate(pathToPurge) | ||
return res.json({ code: 200, message: 'success' }) | ||
} catch (err) { | ||
return res.status(500).send({ code: 500, message: err.message }) | ||
} | ||
} |