Closed perkee closed 11 months ago
I'm outside of the edit window, but just to add: this isn't an issue of the nix packages version of elm
being extremely weird; if I install elm with the official elm installer from elm-lang.org then call it directly with /usr/local/bin/elm make src/Main.elm --output=main.html
it's the same issue.
Another user on the elm slack was not able to reproduce this problem from source but did see the same issue when I sent the compiled HTML file. So in the interests of debugging, I'm attaching it here. Github doesn't allow html attachments so here's a pastbin link https://pastebin.com/tUBCMgVM
There does seem to be some difference in Elm compiler versions somehow. I tried opening your HTML file locally and got the same errors; I compiled your source files with Elm 0.19.1 on Linux and it was fine. When I did a diff of the two HTML files against each other I see a bunch of stuff in the bad one that seems to be related to working around browser extensions; there's a new created_by_elm
tag and some move complex logic that tries to skip over DOM nodes that Elm didn't itself create, e.g.:
Here's a Gist with the working HTML so you can do a diff yourself: https://gist.github.com/ianmackenzie/e8c9517106736e90bff772bdbab4bc9a
I'm not sure if there's much elm-3d-scene
can really do here...my only guess is that elm-3d-scene
uses a Html.Keyed.node "div"
as the top-level HTML element, and maybe there's some quirk where some of the Elm virtual DOM logic doesn't work well if the very top-level element in <body>
is a keyed node instead of a normal one? What happens if you try compiling with an additional dummy wrapper div
around the Scene3d.cloudy
call?
I've got the answer! It's not you, it's me! While I never applied jinjor's vdom patch, it was applied to my ~/.elm
by work tooling!! And that patch breaks this!
Ah OK yeah it could be that patch doesn't work properly with keyed HTML nodes or something. Still kinda curious if a wrapper <div>
would help though - that would be easy enough to add. (And as it happens I should have a new version of elm-3d-scene
coming out sometime in the next month or so, so now's a pretty decent time to sneak something like that in.)
I guess to avoid accidentally breaking code that somehow relies on the existing elm-3d-scene
internal HTML structure (e.g. via CSS selectors) maybe it's best to leave the internals as is...but if you do end up trying a wrapper <div>
with the virtual DOM patch and that fixes things, let me know and I can add a note to the README or docs or something.
if you do end up trying a wrapper
with the virtual DOM patch and that fixes things, let me know and I can add a note to the README or docs or something.Tragically wrapping it by
div [] [ scene model ]
does nothing to alleviate the problem. I have opened an issue in the patch repo https://github.com/jinjor/elm-break-dom/issues/35
The Problem
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
Build 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 modelRender it in Ellie
This whole thing came about because I tried to take a somewhat complicated Ellie I had worked on and work on it locally. That Ellie is a fork of the HelloWorld example from this package's examples/README.md document.
Here is an Ellie of the minimum example above that does not throw any errors. For that one I made sure to start from scratch on Ellie in case there was some weird state that fixes this problem in the HelloWorld example that carried through.