gioboa / qwik-dream-demo

https://qwik-dream-demo.pages.dev/
28 stars 11 forks source link

Cloudflare doesn't load chunks #37

Closed gioboa closed 1 year ago

gioboa commented 1 year ago

The host application fails requests to cloudflare pages
Screenshot 2022-12-11 at 22 00 48
with this function the host will proxy this request to https://qwik-dream-hero.pages.dev/hero/build/q-a08f62fe.js
Screenshot 2022-12-11 at 22 06 47

this is my cloudflare page

Screenshot 2022-12-11 at 22 09 48

locally it works
Screenshot 2022-12-11 at 22 12 59

@dario-piotrowicz have you got any idea?

dario-piotrowicz commented 1 year ago

@gioboa I'm sorry I am not completely sure, strangely I don't get a 404 for that file, but a 200: Screenshot at 2022-12-11 21-48-28

but the 200 as the response only contains the url as a string :confused: Screenshot at 2022-12-11 21-49-21

and there are other js files there that fail to get fetched...

I imagine you've tried re-deploying the pages apps just in case?

gioboa commented 1 year ago

Yep, you're right. I will deploy again all the apps

-- UPDATE --

I deployed all the apps

gioboa commented 1 year ago

I can't understand the right URL to get that file 🤔

dario-piotrowicz commented 1 year ago

I'm not sure what the issue is... :confused:

I have a feeling that the problem lies with the qwikCity adapter used for the various mfes, but not the host as that seems fine, also from what I can tell from the code it does seem to be forwarding the requests correctly to the mfes.

it does look like the mfes aren't returning the assets correctly like for example this one: https://qwik-dream-hero.pages.dev/build/q-a08f62fe.js

also if you go to the product one: https://qwik-dream-product.pages.dev/product/ you can see that it doesn't download and js at all, there isn't any js being downloaded or anything...

so I definitely think that the non-host microfrontends' qwikCity or deployment is the one causing the issues (but I am not sure why....)

dario-piotrowicz commented 1 year ago

~@gioboa out of curiosity, do you know if it worked before this change? https://github.com/gioboa/qwik-dream-demo/commit/5433cb0f08af64d5fe4adcef85651eac2ca1ccde could that have broken it?~

nah never mind as I said below this is probably not the issue :confused:

gioboa commented 1 year ago

https://qwik-dream-product.pages.dev/product/ and other mfes are deployed without the loader so they don't download any ja files. That's because is a host tasks. I can't figured out why in preview mode it works

dario-piotrowicz commented 1 year ago

I can't understand the right URL to get that file thinking

regarding q-a08f62fe.js, I think that the right url for it is: https://qwik-dream-hero.pages.dev/build/q-a08f62fe.js

the demo/host fetches from https://qwik-dream-demo.pages.dev/hero/build/q-a08f62fe.js and then in the host pages functions the getTargetUrl basically strips away the /hero/ part and replaces the base url (resulting in https://qwik-dream-hero.pages.dev/build/q-a08f62fe.js)

so that's why I said that I think that the host is fine by the other micro frontends have some issues :thinking:

gioboa commented 1 year ago

@gioboa out of curiosity, do you know if it worked before this change? 5433cb0 could that have broken it?

I will do this test tomorrow but I think that the problem is caused by the deps update

gioboa commented 1 year ago

Btw you can deploy the applications in your cloudflare account to test them 👍

dario-piotrowicz commented 1 year ago

@gioboa out of curiosity, do you know if it worked before this change? 5433cb0 could that have broken it?

I will do this test tomorrow but I think that the problem is caused by the deps update

@gioboa don't worry about that one as I said I don't really think that that is the issue

by the way, adam did update the cloudflare-pages adaptor recently: https://github.com/BuilderIO/qwik/commit/7f560eb6a8e23d8dac6ef94023fd7c158823bd4a# I wonder if that could have broken things?

did you deploy the app in the past? or was this your first attempt?

dario-piotrowicz commented 1 year ago

@gioboa I actually think that this is wrong: https://github.com/gioboa/qwik-dream-demo/blob/5433cb0f08af64d5fe4adcef85651eac2ca1ccde/libs/shared/cloudflare.utils.ts#L4

the remotes are just localhost urls are they not? https://github.com/gioboa/qwik-dream-demo/blob/7d654834977a5101dc43513c266fec3b0c245f74/libs/shared/remotes.ts

I can actually see the localhosts appearing in the cloudflare entry js: Screenshot at 2022-12-11 23-40-28

dario-piotrowicz commented 1 year ago

Btw you can deploy the applications in your cloudflare account to test them +1

yes I can but we may need to add some env of configuration if we want different people to be able to deploy the app, because by your deployments you've already taken the standard page urls (https://qwik-dream-demo.pages.dev/, https://qwik-dream-hero.pages.dev/, https://qwik-dream-products.pages.dev/....) so if other people create the same projects they will receive different urls (for example I created a cart one and this is the url I've been given: https://qwik-dream-cart-4yq.pages.dev/).

So I think we will need to have a way to configure the urls so that the host will know which urls for the mfes to use.

gioboa commented 1 year ago

something change in this commit https://github.com/gioboa/qwik-dream-demo/commit/4de04ac12a22d53472ba0bce3393c74f3d0fb738 before libs update this endpoint works

/build/.js after is not working anymore
gioboa commented 1 year ago

We solved it by changing this piece of code in the library @builder.io/qwik-city: "0.0.128" _nodemodules/@builder.io/qwik-city/middleware/cloudflare-pages/index.mjs if (isStaticPath(url.pathname)) to if (isStaticPath(url.pathname) || /.(js)$/.test(url.pathname)) I think in the next release will be fixed automatically.

dario-piotrowicz commented 1 year ago

@gioboa I actually think that this is wrong:

https://github.com/gioboa/qwik-dream-demo/blob/5433cb0f08af64d5fe4adcef85651eac2ca1ccde/libs/shared/cloudflare.utils.ts#L4

the remotes are just localhost urls are they not? https://github.com/gioboa/qwik-dream-demo/blob/7d654834977a5101dc43513c266fec3b0c245f74/libs/shared/remotes.ts

I can actually see the localhosts appearing in the cloudflare entry js: Screenshot at 2022-12-11 23-40-28

yeah... I was probably wrong here then I guess :thinking:

gioboa commented 1 year ago

Btw I reverted the commit https://github.com/gioboa/qwik-dream-demo/commit/7ee038c7abac8b8cefd8a990afbf4d9736541244 😅