tinloof / sanity-kit

84 stars 12 forks source link

Error: Failed to construct 'URL': Invalid URL #46

Open gercordero opened 7 months ago

gercordero commented 7 months ago

Hello, I was trying out your sections example but the Pages preview tab is crashing for me. I haven't changed anything from the example apart from adding my own .env variables.

This is the error I'm getting:

Error: Failed to construct 'URL': Invalid URL
TypeError: Failed to construct 'URL': Invalid URL
    at eval (webpack-internal:///(app-pages-browser)/./node_modules/@tinloof/sanity-studio/node_modules/@sanity/presentation/dist/_chunks-es/PresentationTool.js:76:24452)
    at mountMemo (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:12778:19)
    at Object.useMemo (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:13504:16)
    at useMemo (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-experimental/cjs/react.development.js:2588:21)
    at Jn (webpack-internal:///(app-pages-browser)/./node_modules/@tinloof/sanity-studio/node_modules/@sanity/presentation/dist/_chunks-es/PresentationTool.js:76:24245)
    at ir (webpack-internal:///(app-pages-browser)/./node_modules/@tinloof/sanity-studio/node_modules/@sanity/presentation/dist/_chunks-es/PresentationTool.js:78:2322)
    at renderWithHooks (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:11182:18)
    at updateFunctionComponent (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:16603:20)
    at mountLazyComponent (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:17078:17)
    at beginWork$1 (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:18782:16)
    at beginWork (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:27349:14)
    at performUnitOfWork (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:26089:12)
    at workLoopSync (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:25805:5)
    at renderRootSync (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:25760:7)
    at recoverFromConcurrentError (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:24934:20)
    at performSyncWorkOnRoot (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:25236:20)
    at flushSyncWorkAcrossRoots_impl (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:7791:13)
    at flushSyncWorkOnAllRoots (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:7751:3)
    at processRootScheduleInMicrotask (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:7896:3)
    at eval (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom.development.js:8067:7)

Here you also have a video:

https://github.com/tinloof/sanity-kit/assets/13878860/70cab0d4-4a3e-424c-b752-7e97a36b5a24

Any clues on what is going one? Thank you!

oybek-daniyarov commented 7 months ago

@gercordero I also started getting this issue after I upgraded Sanity to ^3.40.0

oybek-daniyarov commented 7 months ago

@gercordero, in the sanity config, please include the origin

const SANITY_STUDIO_PREVIEW_URL = (
    process.env.SANITY_STUDIO_PREVIEW_URL
    || 'http://localhost:3000'
)
pages({
      previewUrl: {
        origin: SANITY_STUDIO_PREVIEW_URL,
        previewMode: {
          enable: '/api/draft',
        },
      },
      creatablePages: ['page'],
})
gercordero commented 6 months ago

@oybek-daniyarov Legend, that fixed it! Should I leave this issue open so this can be documented in the READ.me file?