DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
21.04k stars 817 forks source link

Client-side error only in release mode on 0.6.0-alpha.2: Uncaught TypeError: root is undefined / Cannot read properties of undefined (reading 'appendChild') #2926

Open david-boles opened 1 month ago

david-boles commented 1 month ago

Problem

Client-side panic when hydrating a release (not debug) fullstack build on 0.6.0-alpha.2:

Chrome:

inline0.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'appendChild')
    at RawInterpreter.appendChildren (inline0.js:2:2759)
    at RawInterpreter.run (inline0.js:148:46)
    at imports.wbg.__wbg_run_a2a42ac573bdb8ba (specs.js:723:14)
    at specs_bg.wasm:0x15e0b0
    at specs_bg.wasm:0xb5f74
    at specs_bg.wasm:0xdf35b
    at specs_bg.wasm:0x5d5ea
    at specs_bg.wasm:0x4a40c
    at specs_bg.wasm:0xdb62f
    at specs_bg.wasm:0x158ee1

Steps To Reproduce

Unsure; it doesn't happen in a new project. Will try to narrow down what's causing it in mine.

Expected behavior

No panic.

Environment:

david-boles commented 1 month ago

I'm having some trouble producing a minimal reproducible example, so I think there's more playing a role here, but it seems to be related to use_server_future returning RenderError::Suspended (and me propagating that back up) on the client. Just dropping the return value from use_server_future makes this error go away. Although the initial return value from use_server_future doesn't change between release and not-release.

david-boles commented 1 month ago

Welp, this is odd. Adding:

tokio::time::sleep(Duration::from_millis(1000)).await;

To my #[server] function being called through use_server_future fixes it. Maybe I'm hitting some sort of race condition on the client?

I notice that that does delay the final part:

<div id="ds-0-r" hidden><!--node-id0-->root<!--#--></div><script>window.dx_hydrate([0], "...")</script></body>
</html>

Getting delivered and thus hydration starting.