Hello everyone ![]()
I’m experiencing an issue with the Visual Editor iframe preview on Storyblok that started after migrating our Next.js website hosting from Cloudflare to Vercel. The preview worked correctly on Cloudflare but now shows a flash of the page content followed by a blank screen. Localhost is working correctly with the preview functionality.
Environment:
- Framework: Next.js 14.2.30 (App Router)
- Hosting: Vercel (previously Cloudflare)
- Storyblok SDK:
@storyblok/reactv5.4.18 - Node: 22+
Behavior:
Website loads correctly when accessed directly on Vercel (not in iframe)
Visual Editor iframe preview: page flashes briefly, then goes blank with JavaScript errors
Console Error in iframe:
TypeError: Cannot read properties of undefined (reading ‘min_xl’) at 17152-ce76e94fcad2350d.js:1:41518 at ex (32209-b261eec7d073bfcb.js:1:333137) at e.generateAndInjectStyles (32209-b261eec7d073bfcb.js:1:334219)
This error occurs in styled-components, indicating that the theme context (props.theme) is undefined when accessed inside the iframe, even though ThemeProvider is correctly wrapping the application.
What I tried (none resolved the issue):
1 - CSP Headers: Added all Storyblok domains to Content-Security-Policy:
- frame-ancestors:
*.storyblok.com, https://app.storyblok.com - script-src: Storyblok domains
- connect-src: https://api.storyblok.com, https://gapi.storyblok.com
- style-src: Storyblok domains
2 - Theme fixes attempted:
- Hardcoded entire theme object
- Added optional chaining (
?.) to all theme property accesses - Result: After fixing breakpoints, errors shifted to colors, then fonts, then DOM manipulation errors (appendChild, removeChild)
Key observation:
The styled-components ThemeProvider context appears to not reach components when rendered inside the Storyblok iframe, even though:
- The same code works perfectly when accessed directly (not in iframe)
- The same code worked when hosted on Cloudflare
Questions:
- Are there known differences in how Vercel serves pages in iframes vs Cloudflare that could origin this?
- Is there additional configuration required for an iframe with Next.js App Router on Vercel?
- Are there any headers or settings specific to Vercel deployments that I might be missing?
