-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: edge runtime dynamic code eval (#1831)
- Loading branch information
Showing
6 changed files
with
47 additions
and
5 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
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
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,16 @@ | ||
/** | ||
* Some of the exports on index.ts causes errors on the edge runtime, so we omit them here. | ||
*/ | ||
|
||
import type {VisualEditingProps} from './visual-editing' | ||
|
||
export * from './client' | ||
export * from '@portabletext/react' | ||
export * from '@sanity/next-loader' | ||
export {defineQuery, default as groq} from 'groq' | ||
export type {VisualEditingProps} from 'next-sanity/visual-editing/client-component' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function VisualEditing(_props: VisualEditingProps): React.ReactNode { | ||
throw new TypeError('VisualEditing is not supported on the edge runtime') | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/next-sanity/src/visual-editing/client-component/VisualEditingLazy.tsx
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,21 @@ | ||
/** | ||
* | ||
* If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`), | ||
* or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet) | ||
* we could use `dynamic(() => import('...), {ssr: false})` here. | ||
* Since we can't, we need to use a lazy import and Suspense ourself. | ||
*/ | ||
|
||
import {lazy, Suspense} from 'react' | ||
|
||
import type {VisualEditingProps} from './VisualEditing' | ||
|
||
const VisualEditingClientComponent = lazy(() => import('./VisualEditing')) | ||
|
||
export function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode { | ||
return ( | ||
<Suspense fallback={null}> | ||
<VisualEditingClientComponent {...props} /> | ||
</Suspense> | ||
) | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/next-sanity/src/visual-editing/client-component/index.ts
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
'use client' | ||
|
||
export type {VisualEditingProps} from './VisualEditing' | ||
export {default} from './VisualEditing' | ||
export {VisualEditingLazyClientComponent as default} from './VisualEditingLazy' |
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