# Why do I get a runtime error

**URL:** https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243
**Category:** Learn
**Created:** [March 2, 2019, 11:24am UTC](https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243 "2019-03-02T11:24:13Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![uweg](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/uweg/32/2541_2.png) [@uweg](https://discourse.elm-lang.org/u/uweg)
#### Post date: [March 2, 2019, 11:24am UTC](https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243/1 "2019-03-02T11:24:13Z")

</div>

I was fiddling around with Elm a little bit and like it so far.However, I ran into a problem an think you might be able to tell me how to fix it.

[https://ellie-app.com/4S2bzhfphyJa1](https://ellie-app.com/4S2bzhfphyJa1)

As soon as i have some valid XML on the left side, there is an error in the console. The error is caused by line 62. Since it is really hard to debug Elm (at least I had nod yet figured out how to do it), I’m not sure if this is a bug in elm-ui or if i did something wrong.

Any thoughts?

---

<div class="post-metadata">

### Author: ![albertdahlin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/albertdahlin/32/868_2.png) [@albertdahlin](https://discourse.elm-lang.org/u/albertdahlin)
#### Post date: [March 2, 2019, 11:35am UTC](https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243/2 "2019-03-02T11:35:49Z")

</div>

Something seems to be wrong with `HA.contenteditable`

When I change row 62 to this it works:

```elm
E.htmlAttribute (HA.attribute "contenteditable" "true" )

```

---

<div class="post-metadata">

### Author: ![uweg](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/uweg/32/2541_2.png) [@uweg](https://discourse.elm-lang.org/u/uweg)
#### Post date: [March 2, 2019, 12:38pm UTC](https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243/3 "2019-03-02T12:38:20Z")

</div>

That’s a good idea, thank you!

But I still wonder why the other ends in an error, even if it should do the same thing. I think it’s a bug in one of the involved frameworks.

---

<div class="post-metadata">

### Author: ![harrysarson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/harrysarson/32/1305_2.png) [@harrysarson](https://discourse.elm-lang.org/u/harrysarson)
#### Post date: [March 2, 2019, 3:45pm UTC](https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243/4 "2019-03-02T15:45:17Z")

</div>

I have reduced your problem: [https://ellie-app.com/4S7MDdqsNQba1](https://ellie-app.com/4S7MDdqsNQba1)

Swap `False` for `True` on line 39 to get a runtime error.

It is unrelated to either the xml or style-elements packages. There error relates to `elm/virtual-dom` and how it handles `properties`.

```elm
module Main exposing (main)

import Browser
import Html exposing (Html)
import Html.Attributes as HA
import Task
import Json.Encode

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

init : () -> ( Bool, Cmd () )
init flags =
    ( False
    , Task.perform identity (Task.succeed ())
    )

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

view : Bool -> Html msg
view loaded =
    case loaded of
        True ->
            Html.div [] []

        False ->
            Html.div
                [ (if False then
                       (HA.property "contentEditable" (Json.Encode.bool True))
                   else
                       (HA.attribute "contentEditable" "true")
                  )
                ]
                [Html.text "initial"]

```

---

<div class="post-metadata">

### Author: ![harrysarson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/harrysarson/32/1305_2.png) [@harrysarson](https://discourse.elm-lang.org/u/harrysarson)
#### Post date: [March 6, 2019, 11:22am UTC](https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243/5 "2019-03-06T11:22:39Z")

</div>

Github issue: [https://github.com/elm/virtual-dom/issues/151](https://github.com/elm/virtual-dom/issues/151)

---

<div class="post-metadata">

### Author: ![harrysarson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/harrysarson/32/1305_2.png) [@harrysarson](https://discourse.elm-lang.org/u/harrysarson)
#### Post date: [March 13, 2019, 12:00am UTC](https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243/6 "2019-03-13T00:00:43Z")

</div>

Optimistic bump 🙂

---

<div class="post-metadata">

### Author: ![dmy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dmy/32/702_2.png) [@dmy](https://discourse.elm-lang.org/u/dmy)
#### Post date: [March 13, 2019, 8:48am UTC](https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243/7 "2019-03-13T08:48:56Z")

</div>

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

```auto
node.contentEditable = null;

```

which is not supported for `contentEditable`.

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

```auto
document.body.contentEditable = null

```

This is a known bug traced here: [bug #104](https://github.com/elm/virtual-dom/issues/104) (specifically [#81](https://github.com/elm/virtual-dom/issues/81))

I guess that the work-arounds are:

- use `attribute "contenteditable"` instead
- or set the property to `Encode.bool False` instead of removing it from your attributes
- or use `Html.Keyed` with a different identifier to force the `div` to be rebuilt

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)
#### Post date: [March 23, 2019, 9:00am UTC](https://discourse.elm-lang.org/t/why-do-i-get-a-runtime-error/3243/8 "2019-03-23T09:00:39Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
