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

Docs: potential preview-mode error on production build #34129

Closed
mingyeungs opened this issue Feb 9, 2022 · 5 comments · Fixed by #34142
Closed

Docs: potential preview-mode error on production build #34129

mingyeungs opened this issue Feb 9, 2022 · 5 comments · Fixed by #34142
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@mingyeungs
Copy link

What is the improvement or update you wish to see?

Under the Clear the preview mode cookies section, It might be worth mentioning one should NOT use <Link href="/api/to/clear/cookies/">...</Link> to clear the preview-mode cookies.

Is there any context that might help us understand?

<Link /> are automatically prefetched in production built. When <Link href="/api/to/clear/cookies/">Exit Preview</Link> button is shown in preview mode, it gets prefetched and the preview cookies are cleared immediately.

In my case, the server is crashed whenever user enters preview mode (due to res.redirect() logic in my /preview/ api); in other setup, it might cause other unexpected behaviour.

The fix is simple though, simply use an tag and the issue is gone.

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/advanced-features/preview-mode#clear-the-preview-mode-cookies

@mingyeungs mingyeungs added the Documentation Related to Next.js' official documentation. label Feb 9, 2022
@balazsorban44 balazsorban44 added area: documentation good first issue Easy to fix issues, good for newcomers and removed Documentation Related to Next.js' official documentation. labels Feb 9, 2022
@balazsorban44
Copy link
Member

Sounds good! Here is the file if anyone wanted to open a PR to fix this: https://github.com/vercel/next.js/blob/canary/docs/advanced-features/preview-mode.md

@mattyocode
Copy link
Contributor

mattyocode commented Feb 9, 2022

Does using a Link component with prefetch={false} solve the issue?

@mattyocode
Copy link
Contributor

I'm happy to add a note about it to the docs

mattyocode added a commit to mattyocode/next.js that referenced this issue Feb 9, 2022
Add note to 'Clear preview mode cookies' that explains the need to pass `prefetch={false}` to `Link` component to prevent clearing cookies accidentally.
(Docs: potential preview-mode error on production build vercel#34129)
@kodiakhq kodiakhq bot closed this as completed in #34142 Feb 9, 2022
kodiakhq bot pushed a commit that referenced this issue Feb 9, 2022
…(issue #34129) (#34142)

Add note that explains the need to pass `prefetch={false}` to `Link` component to prevent clearing cookies accidentally
(responding to issue "Docs: potential preview-mode error on production build #34129").

Note as follows:

> **Note:** If calling this route using `Link` component, you must pass in `prefetch={false}` to prevent calling `clearPreviewData` during prefetch.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ x] Make sure the linting passes by running `yarn lint`
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
4 participants
@mingyeungs @balazsorban44 @mattyocode and others