Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set cookie path when entering preview mode #552

Merged
merged 4 commits into from
Jul 11, 2023

Conversation

nicholasio
Copy link
Member

@nicholasio nicholasio commented Jul 11, 2023

Description of the Change

This PR improves the Next.js preview cookie handling.

First of all, it sets the preview cookie to expire within 5 minutes which aligns with the JWT token expiration.

Secondly, it will narrow the cookie to the post path being previewed so that context.preview is not true for other paths and thus avoiding bypassing getStaticProps (among other potential issues) until the cookies are cleared (either expires or the browser closes).

This would also let us eventually get rid of the requirement of having "-preview=true" in the URL.

How to test the Change

Preview a post and check if the cookies __prerender_bypass and __next_preview_data has path set to the actual path being previewed.
image

Alternatively, you can also test with a production build whether getStaticProps are not running for every request after previewing a post.

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@changeset-bot
Copy link

changeset-bot bot commented Jul 11, 2023

🦋 Changeset detected

Latest commit: 30ba50c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@headstartwp/next Minor
@headstartwp/headstartwp Patch
@headstartwp/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jul 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headstarwp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2023 4:16am

@github-actions
Copy link
Contributor

📦 Next.js Bundle Analysis for @10up/headless_framework

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

1 similar comment
@github-actions
Copy link
Contributor

📦 Next.js Bundle Analysis for @10up/headless_framework

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@github-actions
Copy link
Contributor

📦 Next.js Bundle Analysis for @10up/headless_framework

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@nicholasio nicholasio requested a review from lucymtc July 11, 2023 04:14
@github-actions
Copy link
Contributor

📦 Next.js Bundle Analysis for @10up/headless_framework

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@nicholasio nicholasio merged commit 569662b into develop Jul 11, 2023
6 checks passed
@nicholasio nicholasio deleted the feat/preview-cookie-improvements branch July 11, 2023 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant