ITADN

Invalid hook call during dev SSR with @astrojs/cloudflare and a React island

#17834Openvalkum 创建于 4 天前
ecosystem: upstream- P2: has workaroundfeat: ssrfeat: devpkg: cloudflaretriage: unable to reproduce
V
valkumcommented
### Astro Info ```block Astro v7.2.1 Node v22.21.1 System macOS (arm64) Package Manager bun Output static Adapter @astrojs/cloudflare Integrations @astrojs/react ``` ### If this issue only occurs in one browser, which browser is a problem? _No response_ ### Describe the Bug This is a follow-up to https://github.com/withastro/astro/issues/16529, which was closed with "We believe this is likely fixed in Astro 7." The error is still present on Astro 7.2.1. Repro: 1. bun install (or npm install) 2. rm -rf node_modules/.vite 3. bunx astro dev 4. Request the page one time: curl -s http://localhost:4321/ | wc -c 5. Request the page a second time. The first response is 420 bytes and holds no astro-island element. The server logs: ``` [ERROR] [vite] Invalid hook call. Hooks can only be called inside of the body of a function component. [ERROR] [vite] TypeError: Cannot read properties of null (reading 'useState') at Object.exports.useState (node_modules/react/cjs/react.development.js:1263:33) at ReproCounter (src/components/ReproCounter.tsx:4:29) at renderWithHooks (node_modules/.vite/deps_ssr/react-dom_server.js:2797:19) ``` This is caused by using React and the Cloudflare adapter. The docs do not mention any caveats when using both. ### What's the expected result? The first response renders the island. ### Link to Minimal Reproducible Example https://github.com/valkum/astro-7-react-cloudflare-issue ### Participation - [x] I am willing to submit a pull request for this issue.
6 条评论