-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Html.Lazy always recomputes inner functions #201
Comments
I think this is technically a compiler bug, by the way. The code in Html.Lazy (or, more precisely, I doubt this is browser-specific behavior, but I tested this only on FireFox. |
Also, just to make things even more complex here, if the inner view helper did close on any Elm variables besides the arguments (it doesn't here, but it could in other scenarios), then the Elm compiler would have to emit the inner function the way it does now. In that case there's no way that I can think of to emit code that is friendly to Html.Lazy.lazy. In other words Html.Lazy would always have to punt on optimizations due to seeing "different" functions (even though it's the same JS code). I think in most of these scenarios the relevant model data would be changing anyway, but sometimes it will be valid code that just uses maybe one mostly non-changing field from the model. So it's possible that the solution here is to just prevent folks from applying Html.Lazy.lazy to any function in the |
I opened elm/compiler#2020 in hopes that the compiler could be changed here to support |
As you can see, equality here is by reference, not by value. Anything in the let (a function, a list, a record) will not be equal by reference to its value the last incarnation of the function. |
I'm willing to commission somebody to implement a version of Many of the views in my apps take big responsibilities, and consequently, take big records as configurations. It makes things waaay more readable if the arguments are "named" this way. |
The virtual DOM will always recompute any function that's inside a
let
, even if it's wrapped insideHtml.Lazy.lazy
.Here is the SSCCE:
https://github.com/showell/elm-start/commits/html-lazy-is-broken-for-let-functions
There are two commits to note here:
The last commit shows how it should work. Run this without building index.html. Instead, just use the index.html that is checked in. (If you look at the commit, you can see my proposed changes to index.html to avoid the bug, and there's some more detail.)
The second to last commit is the repro. Or, really, you can actually just rebuild the last commit. Either way, if you don't use my modified index.html, you can type around in the textarea and see it recomputing
lotsOfFreds
over and over again.The example in the repro is a full program, but you can get the gist here:
The problem happens deep in the virtual DOM implementation. The virtual DOM is comparing two different copies of
lotsOfFreds
.The text was updated successfully, but these errors were encountered: