Skip to content

Commit

Permalink
[web] Use defer instead of async (#197)
Browse files Browse the repository at this point in the history
Sometimes the web repl will fail with this error message in the console:
```
Uncaught (in promise) TypeError: rinkDiv is null
    Immutable 2
        pushError
        <anonymous>
index.1d6d65d8.js:111:3
```
To reproduce in Firefox, ctrl+click on a link to `rinkcalc.app`, such as
[this one](https://rinkcalc.app/?q=(c/sqrt(4.5))/2.4GHz/20).

Seems like it's caused by a race condition. The script is in the
`<head>` element and is marked `async`. Async scripts apparently run in
parallel to parsing the page. Changing this to `defer` fixes it for me.
  • Loading branch information
tiffany352 authored Feb 9, 2025
1 parent 891296b commit 2459ee9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion web/plugins/vite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ while files[i] do
local script = HTML.create_element("script")
HTML.set_attribute(script, "src", "/immutable/" .. file)
HTML.set_attribute(script, "data-wasm", "/" .. wasm_out)
HTML.set_attribute(script, "async", "")
HTML.set_attribute(script, "defer", "")
local head = HTML.select_one(page, "head")
HTML.append_child(head, script)
end
Expand Down

0 comments on commit 2459ee9

Please sign in to comment.