ursi / purescript-elmish

this will have its own name eventually
https://github.com/ursi/purescript-package-set
3 stars 0 forks source link

Keyed elements seem to be borked if CSS is too naughty #4

Closed Quelklef closed 3 years ago

Quelklef commented 3 years ago

Synopsis

The first keyed element is stripped of its styling when the two are swapped

Notes

The relevant factors seem to be:

  1. using a keyed element; and
  2. having different CSS for the two elements

If an unkeyed element is used, or if the two <p>s are rendered with the same background color, the bug does not manifest.

Also:

Code

module Main (main) where

import Prelude
import Data.Tuple.Nested ((/\))

import Platform (Program, app)
import Attribute as A
import Html as H
import Css as S

main :: Program Unit (Array String) Unit
main = app
  { init: \_ -> pure [ "A", "B" ]
  , update: \strings _ -> pure [ "B", "A" ]
  , subscriptions: const mempty
  , view: \strings ->
      { head: [ ]
      , body:
        [ H.div [ ]
          [ H.buttonS
            [ S.active [ S.background "black" ] ]
            [ A.onClick unit ]
            [ H.text "swap" ]
          , H.keyed "div"
            [ ]
            ( strings <#> (\string ->
                string
                  /\
                H.pS
                [ S.border "1px solid black"
                , S.background $ if string == "A" then "cyan" else "pink"
                ]
                [ ]
                [ H.text string ]
            ) )
          ]
        ]
      }
  }
ursi commented 3 years ago

Oh wow, I guess github closes issue n automatically if you name your commit Fix #n. But yeah, fixed :+1: . Just needed to swap two args around.

Quelklef commented 3 years ago

oh, wow, that's a tiny fix!

thanks! :tada: