withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.43k stars 2.46k forks source link

Astro 3.0 breaks React client component #8314

Closed jorgebenaventee closed 1 year ago

jorgebenaventee commented 1 year ago

Astro info

Astro version            v3.0.3
Package manager          pnpm
Platform                 win32
Architecture             x64
Adapter                  @astrojs/node
Integrations             @astrojs/tailwind, @astrojs/react

What browser are you using?

Chrome

Describe the Bug

After upgrading to Astro 3.0 while using node adapter and hybrid output, it is adding before-hydration-url=/ attribute to React client components. This makes childrenConnectedCallback try to import / and breaking the rendering causing the following error message in browser console when running astro preview (Works fine in dev mode)

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

What's the expected result?

I expected my component to render properly

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-bmpb88

Participation

jorgebenaventee commented 1 year ago

Link to Minimal Reproducible Example is not working because Node version is not supported. You can download the project to test locally.

xesrevinu commented 1 year ago

I created a reproducible repository and deployed it to cloudflare pages :) https://astro-react-prod-issue.pages.dev https://github.com/xesrevinu/astro-react-prod-issue

astro-react-prod-issue.pages.dev/:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
(index):3 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://astro-react-prod-issue.pages.dev/
jorgebenaventee commented 1 year ago

I created a reproducible repository and deployed it to cloudflare pages :) https://astro-react-prod-issue.pages.dev https://github.com/xesrevinu/astro-react-prod-issue

astro-react-prod-issue.pages.dev/:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
(index):3 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://astro-react-prod-issue.pages.dev/

Thank you very much!

natemoo-re commented 1 year ago

Thank you for the report! We'll look into this as soon as we can!

JLarky commented 1 year ago

I was able to reproduce this with Vercel serveless adapter as well. You can see that in the last commit I'm changing output from server to hybrid and it stops hydrating it on the client.

I created a reproduction here https://github.com/JLarky/astro-examples/tree/main/astro-3-react-ssr-vercel-bug

expected:

image

instead got this:

image
pijusz commented 1 year ago

I get somewhat similar error: I'm using React components with shadcn's navigation (Mobile and Desktop modals) with: client:load and Mobile Nav also has: client:media="(max-width: 1024px)" In preview I get 2 console errors (in dev mode it works): "SES_UNHANDLED_REJECTION: TypeError: error loading dynamically imported module: URL" And then "Loading module from “URL” was blocked because of a disallowed MIME type (“text/html”)."

ajn404 commented 1 year ago

same error

jln13x commented 1 year ago

I was able to reproduce this with Vercel serveless adapter as well. You can see that in the last commit I'm changing output from server to hybrid and it stops hydrating it on the client.

I created a reproduction here JLarky/astro-examples@main/astro-3-react-ssr-vercel-bug

expected: image

instead got this: image

did it work for you with the output: server ? Because neither works for me.

degun commented 1 year ago

I get the same error with Svelte components.

"@astrojs/node": "^6.0.0", (also "@astrojs/netlify": "^3.0.1",) "@astrojs/svelte": "^4.0.0", "astro": "^3.0.7",

vampaz commented 1 year ago

Same with Vue

pijusz commented 1 year ago

Seems to have been fixed with https://github.com/withastro/astro/pull/8388

benjamin-guibert commented 1 year ago

I get the same issue using hybrid mode with Vercel:

benjamin-guibert commented 1 year ago

Never mind, I was still using Astro version 3.0. I can confirm that the issue is solved for version 3.1.2. Thank you for the fix, you rock! 🚀