Daydreamer-riri / vite-react-ssg

Static-site generation for React on Vite.
https://vite-react-ssg.netlify.app/
MIT License
127 stars 6 forks source link

mock fail because document doesn't contain root #11

Closed thib3113 closed 10 months ago

thib3113 commented 10 months ago

It seems that using mock: true doesn't works .

throw new Error('hydrateRoot(...): Target container is not a DOM element.');
          ^

Error: hydrateRoot(...): Target container is not a DOM element.
    at hydrateRoot (repo\node_modules\.pnpm\react-dom@18.2.0_react@18.2.0\node_modules\react-dom\cjs\react-dom.development.js:29403:11)
    at hydrateRoot$1 (repo\node_modules\.pnpm\react-dom@18.2.0_react@18.2.0\node_modules\react-dom\cjs\react-dom.development.js:29810:10)
    at file:///repo/node_modules/.pnpm/vite-react-ssg@0.5.2_react-dom@18.2.0_react-router-dom@6.21.1_react@18.2.0_vite@5.0.11/node_modules/vite-react-ssg/dist/index.mjs:172:11
    at Object.startTransition (repo\node_modules\.pnpm\react@18.2.0\node_modules\react\cjs\react.development.js:2433:5)
    at file:///repo/node_modules/.pnpm/vite-react-ssg@0.5.2_react-dom@18.2.0_react-router-dom@6.21.1_react@18.2.0_vite@5.0.11/node_modules/vite-react-ssg/dist/index.mjs:171:15

I think the problem came from

      const container = typeof rootContainer === "string" ? document.querySelector(rootContainer) : rootContainer;

here, the document is the default document from JSDomGlobal . And so, doesn't contain the rootContainer

Daydreamer-riri commented 10 months ago

Thanks for pointing this out, it will be fixed soon.