Elm Exactly
Results / elm-virtual-dom /

VirtualDomIssue110LazyRootRedrawTest

Tags:elm19-bug

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 pass

Issue: elm/virtual-dom#110

A top-level `Html.Lazy.lazy` view whose root node is redrawn loses track of the root DOM node.

<https://github.com/elm/virtual-dom/issues/110>

When the view is `lazy f model` and `f` changes the root element (here `h4` to `div`), the
thunk patch never gets a DOM node in `_VirtualDom_addDomNodes`, so `_VirtualDom_applyPatchesHelp`
does not return the new root node. `Browser.element` keeps patching the old, detached `h4`, and
the next patch that touches a child crashes. Elm 0.19.1 (elm/virtual-dom 1.0.5) throws a
TypeError while rendering step 2, so step 3 is never reached; it should render every step.

Results

elm-0.19.1

failran in 148 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
step: 1
step: 2
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3775
			var theEnd = domNode.childNodes[i];
			                     ^

TypeError: Cannot read properties of undefined (reading 'childNodes')
    at _VirtualDom_applyPatch (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3775:25)
    at _VirtualDom_applyPatchesHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3725:17)
    at _VirtualDom_applyPatch (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3750:11)
    at _VirtualDom_applyPatchesHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3725:17)
    at _VirtualDom_applyPatches (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3716:9)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3971:15
    at Timeout.updateIfNeeded [as _onTimeout] (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:4040:56)
    at listOnTimeout (node:internal/timers:585:17)
    at process.processTimers (node:internal/timers:521:7)

Node.js v22.23.5

elm-0.19.2

failran in 148 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
step: 1
step: 2
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3775
			var theEnd = domNode.childNodes[i];
			                     ^

TypeError: Cannot read properties of undefined (reading 'childNodes')
    at _VirtualDom_applyPatch (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3775:25)
    at _VirtualDom_applyPatchesHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3725:17)
    at _VirtualDom_applyPatch (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3750:11)
    at _VirtualDom_applyPatchesHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3725:17)
    at _VirtualDom_applyPatches (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3716:9)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3971:15
    at Timeout.updateIfNeeded [as _onTimeout] (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:4040:56)
    at listOnTimeout (node:internal/timers:585:17)
    at process.processTimers (node:internal/timers:521:7)

Node.js v22.23.5

elm-0.19.3

failran in 145 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
step: 1
step: 2
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3775
			var theEnd = domNode.childNodes[i];
			                     ^

TypeError: Cannot read properties of undefined (reading 'childNodes')
    at _VirtualDom_applyPatch (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3775:25)
    at _VirtualDom_applyPatchesHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3725:17)
    at _VirtualDom_applyPatch (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3750:11)
    at _VirtualDom_applyPatchesHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3725:17)
    at _VirtualDom_applyPatches (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3716:9)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:3971:15
    at Timeout.updateIfNeeded [as _onTimeout] (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-virtual-dom/out/VirtualDomIssue110LazyRootRedrawTest.js:4040:56)
    at listOnTimeout (node:internal/timers:585:17)
    at process.processTimers (node:internal/timers:521:7)

Node.js v22.23.5

lamdera-1.5.0

passran in 196 ms
Output
step: 1
step: 2
step: 3

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-virtual-dom/VirtualDomIssue110LazyRootRedrawTest] in its title.

Source

The -- CHECK: lines give the expected output.

module VirtualDomIssue110LazyRootRedrawTest exposing (main)
{-| A top-level `Html.Lazy.lazy` view whose root node is redrawn loses track of the root DOM node.
<https://github.com/elm/virtual-dom/issues/110>
When the view is `lazy f model` and `f` changes the root element (here `h4` to `div`), the
thunk patch never gets a DOM node in `_VirtualDom_addDomNodes`, so `_VirtualDom_applyPatchesHelp`
does not return the new root node. `Browser.element` keeps patching the old, detached `h4`, and
the next patch that touches a child crashes. Elm 0.19.1 (elm/virtual-dom 1.0.5) throws a
TypeError while rendering step 2, so step 3 is never reached; it should render every step.
-}
-- TAGS: elm19-bug
-- CHECK: step: 1
-- CHECK: step: 2
-- CHECK: step: 3
import Browser
import Html exposing (Html)
import Html.Lazy
import Process
import Task
{-| Returns an `h4` root at step 0 and a `div` root with nested `span`s afterwards, adding a
second inner `span` from step 2.
-}
view : Int -> Html Int
view step =
case step of
0 ->
Html.h4 [] []
1 ->
Html.div [] [ Html.span [] [ Html.span [] [] ] ]
_ ->
Html.div [] [ Html.span [] [ Html.span [] [], Html.span [] [] ] ]
{-| Sends `step + 1` as the next message after a 50 ms sleep.
-}
next : Int -> Cmd Int
next step =
Task.perform (\_ -> step + 1) (Process.sleep 50)
main : Program () Int Int
main =
Browser.element
{ init = \_ -> ( 0, next 0 )
, view = Html.Lazy.lazy view
, update =
\step _ ->
( Debug.log "step" step
, if step < 3 then
next step
else
Cmd.none
)
, subscriptions = \_ -> Sub.none
}