elm / virtual-dom

The foundation of HTML and SVG in Elm.
https://package.elm-lang.org/packages/elm/virtual-dom/latest
BSD 3-Clause "New" or "Revised" License
209 stars 80 forks source link

VirtualDom.lazy fires when arguments are constants #163

Closed pravdomil closed 4 years ago

pravdomil commented 4 years ago

SSCCE

  1. copy & paste into https://elm-lang.org/try
  2. try to type into inputs
  3. watch browser console for input renders Inputs gets rerendered every time there is onInput event, but they shouldn't because nothing has changed.
    
    module Main exposing (..)

import Browser import Html exposing (Html, div, input, text) import Html.Attributes exposing (value) import Html.Events exposing (onInput) import Html.Lazy exposing (lazy2)

type Msg = NoOp

main : Program () () Msg main = Browser.document { init = _ -> ( (), Cmd.none ) , view = view , update = _ -> ( (), Cmd.none ) , subscriptions = \ -> Sub.none }

view : () -> Browser.Document Msg view model = let list = [ "foo" ]

    t =
        if list == list then
            "list = list"

        else
            "list /= list"
in
{ title = "Hello"
, body =
    [ div [] [ lazy2 lazyView "1" list ]
    , div [] [ lazy2 lazyView "2" list ]
    , div [] [ lazy2 lazyView "3" list ]
    , div [] [ text t ]
    ]
}

lazyView : String -> List String -> Html Msg lazyView val = input [ value (Debug.log "input render" val), onInput (\ -> NoOp) ] []