Menci / vite-plugin-top-level-await

Transform code to support top-level await in normal browsers for Vite.
MIT License
272 stars 15 forks source link

Blank page on first visit of a dynamic client side rendered route #12

Closed Specy closed 2 years ago

Specy commented 2 years ago

I'm having an issue in my sveltekit app where a dynamic page, when first loaded, gives a blank page, if i go back and visit again then it shows correctly.

I removed the top level await plugin and the route works so i'm guessing the issue is coming from there, i'm also using the wasm vite plugin. Is there some configuration i need to do or is this expected?

Specy commented 2 years ago

This is an example of what happens:

https://user-images.githubusercontent.com/59029985/197203653-ac90c121-d43c-4721-9cde-f8c29842b699.mp4

There are no erorrs, everything is loaded correctly

Menci commented 2 years ago

Please upload your project for me to reproduce.

Specy commented 2 years ago

https://github.com/Specy/asm-editor

Here is the repository, I currently commented out the plugin to publish the website but it can just be decommented in the vite config, during development there are no issues, only after building. You can do that by installing dependencies and running npm run build and then npm run preview I set the build target to esnext to be able to publish the website for now

Current Website is hosted at https://asm-editor.specy.app/

Menci commented 2 years ago

Oh I'm not familiar with the frameworks in your project. I'm afraid that I can't investigate this issue...

Could you try finding what caused it? Does the code flow hang or lost in some framework code?

Specy commented 2 years ago

I'm gonna try to check tomorrow, but i'm not sure if i'll be able to find it, i'll let you know

Specy commented 2 years ago

Having a quick look at the code, in this test here: https://github.com/Menci/vite-plugin-top-level-await/blob/8191ae5ba2b44e008f85023b5219d04f19fbfcad/src/transform.spec.ts#L46 and in the makeTryCatch methods, the catch clause is empty, I'm thinking, might it be silently ignoring the error?

Menci commented 2 years ago

Yes, but silently ignoring the exception and skipping awaiting when importing a cyclic dependency with TLA is the expected behavior here. To check if I'm wrong we can modify here to log the caught error.

Specy commented 2 years ago

Why is it expected? Looking at the top level await spec it seems like the default behaviour is to not do anything which will cause a dead lock. You could try to add a console log of the error in the catch clause so to debug it tho. I'm not sure if this is my issue but it's the first thing which might come to mind

Menci commented 2 years ago

I have fixed this issue and will push the changes later. But It's actually nothing to do with that try-catch.

Menci commented 2 years ago

Fixed in v1.2.1.

Specy commented 2 years ago

Ty! it works now