Open perkee opened 1 year ago
WOW OK A solution emerges. It's pretty small. If we apply this repo's patch to VirtualDom.js then we must also similarly patch https://github.com/elm-explorations/webgl/blob/main/src/Elm/Kernel/WebGL.js#L789 to have canvas.created_by_elm = true
right after it. That fixes the whole thing. I went looking in my ~/.elm
for other calls to _VirtualDom_doc.create
but there weren't any others that stood out similarly needing a patch.
The Problem
This was originally filed in the bug tracker for elm-3d-scene but this patch is the root cause https://github.com/ianmackenzie/elm-3d-scene/issues/105
Expected behavior:
Clicking the one button in this example should update the model and otherwise do nothing. The console should not have any errors.
Actual behavior
The console shows many copies of this error (1 per frame in a 60fps browser maybe?)
The line in the stack trace points to
kids.length
in the last for loop in the code below. Lines included above just so it's easier to find in the generated JS. The error will be the same if I build with a JS file as output, only the line numbers will be different naturally.Reproducing the error
Platform
~/.elm/0.19.1/packages/elm/virtual-dom/
patched with this patchBuild command
elm make src/Main.elm --output=main.html
but this persists whether or not I have--debug
or--optimize
or--output=main.js
then include intomain.js
into a handwrittenindex.html
. It persists whether I open the HTML file in the browser (i.e. withfile:///path/to/index.html
) or if I serve it using a minimal webserver (I tend to usepython3 -m http.server 4321
). I have even reproduced it in a lamdera page.elm.json
src/Main.elm
Things that get rid of the Problem
Make scene not depend on the model
In the minimum example above, changing
scene : Model -> Html msg
toscene : Html msg
gets rid of the problem. It means, of course, that the scene cannot change with the values in the model.