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

Runtime Error: Cannot read property 'replaceData' #749

Closed
chancyk opened this Issue Nov 10, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@chancyk

chancyk commented Nov 10, 2016

Windows 7
Chrome 54.0.2840.71

EDIT: I've isolated what's causing the issue, which is clearing the text of a contenteditable div that has a on "input" event attached to it. A reproducible example is included below as a separate comment.

The error persists until the page is reloaded. A Chrome console screenshot follows:

image

which points to the following snippet from applyPatch:

function applyPatch(domNode, patch)
{
	switch (patch.type)
	{
		case 'p-redraw':
			return applyPatchRedraw(domNode, patch.data, patch.eventNode);

		case 'p-facts':
			applyFacts(domNode, patch.eventNode, patch.data);
			return domNode;

		case 'p-text':
			domNode.replaceData(0, domNode.length, patch.data);
			return domNode;
@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Nov 10, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Nov 10, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@chancyk

This comment has been minimized.

Show comment
Hide comment
@chancyk

chancyk Nov 11, 2016

{-| This code will reproduce issue https://github.com/elm-lang/core/issues/749
when the text from either div is cleared. 
-}

import Html exposing (text)
import Html.App as App
import Html.Attributes exposing (contenteditable)
import Html.Events exposing (on)
import Json.Decode as Json


type Msg = HelloUpdate String | WorldUpdate String

update msg model =
  case msg of
    HelloUpdate txt ->
      ( { model | hello = txt }, Cmd.none )

    WorldUpdate txt ->
      ( { model | world = txt }, Cmd.none )

initModel =
  { hello = "hello"
  , world = "world"
  }

view model = 
  Html.div 
    []
    [ Html.div
        [ contenteditable True
        , onInput HelloUpdate
        ]
        [ text model.hello ]
    , Html.div 
        [ contenteditable True
        , onInput WorldUpdate
        ]
        [ text model.world ]
    ]

onInput msg = 
  on "input" (Json.map msg innerHtmlDecoder)

innerHtmlDecoder =
  Json.at ["target", "innerHTML"] Json.string


main =
    App.program
        { init = (initModel, Cmd.none)
        , update = update
        , view = view
        , subscriptions = (\_ -> Sub.none)
        }

chancyk commented Nov 11, 2016

{-| This code will reproduce issue https://github.com/elm-lang/core/issues/749
when the text from either div is cleared. 
-}

import Html exposing (text)
import Html.App as App
import Html.Attributes exposing (contenteditable)
import Html.Events exposing (on)
import Json.Decode as Json


type Msg = HelloUpdate String | WorldUpdate String

update msg model =
  case msg of
    HelloUpdate txt ->
      ( { model | hello = txt }, Cmd.none )

    WorldUpdate txt ->
      ( { model | world = txt }, Cmd.none )

initModel =
  { hello = "hello"
  , world = "world"
  }

view model = 
  Html.div 
    []
    [ Html.div
        [ contenteditable True
        , onInput HelloUpdate
        ]
        [ text model.hello ]
    , Html.div 
        [ contenteditable True
        , onInput WorldUpdate
        ]
        [ text model.world ]
    ]

onInput msg = 
  on "input" (Json.map msg innerHtmlDecoder)

innerHtmlDecoder =
  Json.at ["target", "innerHTML"] Json.string


main =
    App.program
        { init = (initModel, Cmd.none)
        , update = update
        , view = view
        , subscriptions = (\_ -> Sub.none)
        }
@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
Contributor

jvoigtlaender commented Nov 11, 2016

@chancyk

This comment has been minimized.

Show comment
Hide comment

chancyk commented Nov 11, 2016

@chancyk chancyk closed this Nov 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment