next-sanity icon indicating copy to clipboard operation
next-sanity copied to clipboard

feat: new preview mode

Open stipsan opened this issue 3 years ago • 2 comments
trafficstars

Goals:

  • Solve token issues in an elegant way, so Safari users get Preview Mode without hurting perf for Chrome.
  • Don't increase page load JS when preview mode is off.
  • Support React 18 time-slicing.

How to test

npm i next-sanity@new-preview-mode

React 17 example

React 18 example

WIP

Status

  • Works on React 18 with Time Slicing
  • Supports Safari tokens with lazy load of preview mode code.

Challenges

  • Parcel doesn't play nice with React.lazy in library code, we may need to switch to Esbuild or Vite.
  • Moving away from useSubscription to <PreviewMode /> favors optimal load perf and bundlesize over code simplicity, find better helpers and base setups that are less verbose/boilerplate-y.
  • We have 3 different "Preview Modes", the one in our current docs is the cookie/authenticated one that doesn't need a token, but also doesn't work outside Chrome. We need better docs that explains this and guide people into the pit of success.
  • SSR, drafts and hydration is tricky, need better documentation on that as well (it's a hard problem).
  • Need good debugging tools/devtools.

stipsan avatar Aug 12 '22 11:08 stipsan

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

Name Status Preview Updated
next-sanity ✅ Ready (Inspect) Visit Preview Aug 12, 2022 at 4:07PM (UTC)

vercel[bot] avatar Aug 12 '22 11:08 vercel[bot]

📝 Changed routes:

…kie-only/[[...studio]] …ken-only/[[...studio]]
Screenshot of /fixtures/preview-cookie-only/[[...studio]]
(view full size)
Screenshot of /fixtures/preview-token-only/[[...studio]]
(view full size)
/ /studio/[[...index]]
Screenshot of /
(view full size)
Screenshot of /studio/[[...index]]
(view full size)

And 4 other routes:

Commit 9d7dacfbeccd3f4c084c18b955e616e4c71bbb86 (https://next-sanity-owbq390ks.sanity.build).

kmelve avatar Aug 12 '22 13:08 kmelve

We have successfully adapted this in our latest projects and can confirm this is working well for us on Next.js with React 18. However, we couldn't get the Web Previews (Preview mode in iframes) work when in Chrome Incognito and Safari. Upon investigation, I believe it's more of like how these 2 browsers don't permit cookies in iframe. I'm not so sure but just wanted to share this for it might be useful for others. Thanks!

dorelljames avatar Sep 27 '22 10:09 dorelljames