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

Runtime Error: replacing element with property contentEditable #151

Open harrysarson opened 5 years ago

harrysarson commented 5 years ago

SSCCE: https://ellie-app.com/4TNwCtWm5HGa1

module Main exposing (main)

import Browser
import Html exposing (Html)
import Html.Attributes
import Html.Events
import Task
import Json.Encode

main =
    Browser.element
        { init = init
        , update = update
        , view = view
        , subscriptions = always Sub.none
        }

init : () -> ( Bool, Cmd () )
init () =
    ( False , Cmd.none )

update : () -> Bool -> ( Bool, Cmd msg )
update () _ =
    ( True, Cmd.none )

view : Bool -> Html ()
view loaded =
    case loaded of
        True ->
            Html.div [] [ Html.text "It works ok!" ]

        False ->
            Html.div
                [ (if True then
                       (Html.Attributes.property "contentEditable" (Json.Encode.bool True))
                   else
                       (Html.Attributes.attribute "contentEditable" "true")
                  )
                , Html.Events.onClick ()
                ]
                [ Html.text "CLICK ME" ]

Notes


Discourse: https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243/2

rlefevre commented 5 years ago

Elm Virtual Dom diffing algorithm tries to remove the contentEditable property by doing:

node.contentEditable = null;

which is not supported for contentEditable.

You can produce the same error by doing in a javascript console:

document.body.contentEditable = null

This is a known bug traced here: bug #104 (specifically #81)

I guess that the work-arounds are: