From 6e3e2848d3d1c2e719ba0e42b2634688ca5fb5df Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Tue, 11 Jun 2024 18:23:49 +0100 Subject: :bug: Fixed a bug with incorrect keys produced in server component diffs. --- src/lustre/internals/patch.gleam | 8 ++------ src/lustre/internals/vdom.gleam | 10 +++------- 2 files changed, 5 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/lustre/internals/patch.gleam b/src/lustre/internals/patch.gleam index a83d8ae..aeaf16f 100644 --- a/src/lustre/internals/patch.gleam +++ b/src/lustre/internals/patch.gleam @@ -232,13 +232,11 @@ pub fn patch_to_json(patch: Patch(msg)) -> Json { json.preprocessed_array([ json.int(constants.init), json.array(attrs, json.string), - vdom.element_to_json(element), + vdom.element_to_json(element, "0"), ]) } } -import gleam/io - pub fn element_diff_to_json(diff: ElementDiff(msg)) -> Json { json.preprocessed_array([ json.preprocessed_array( @@ -251,11 +249,10 @@ pub fn element_diff_to_json(diff: ElementDiff(msg)) -> Json { |> list.sort(fn(x, y) { key_sort(x.0, y.0) }) |> list.fold([], fn(array, patch) { let #(key, element) = patch - io.debug(key) let json = json.preprocessed_array([ json.string(key), - vdom.element_to_json(element), + vdom.element_to_json(element, key), ]) [json, ..array] @@ -408,7 +405,6 @@ fn fold_event_handlers( list.fold(attrs, handlers, fn(handlers, attr) { case event_handler(attr) { Ok(#(name, handler)) -> { - let name = string.drop_left(name, 2) dict.insert(handlers, key <> "-" <> name, handler) } Error(_) -> handlers diff --git a/src/lustre/internals/vdom.gleam b/src/lustre/internals/vdom.gleam index 181d0b6..20403fe 100644 --- a/src/lustre/internals/vdom.gleam +++ b/src/lustre/internals/vdom.gleam @@ -76,14 +76,10 @@ fn do_element_list_handlers( // CONVERSIONS: JSON ----------------------------------------------------------- -pub fn element_to_json(element: Element(msg)) -> Json { - do_element_to_json(element, "0") -} - -fn do_element_to_json(element: Element(msg), key: String) -> Json { +pub fn element_to_json(element: Element(msg), key: String) -> Json { case element { Text(content) -> json.object([#("content", json.string(content))]) - Map(subtree) -> do_element_to_json(subtree(), key) + Map(subtree) -> element_to_json(subtree(), key) Element(_, namespace, tag, attrs, children, self_closing, void) -> { let attrs = json.preprocessed_array({ @@ -109,7 +105,7 @@ fn do_element_list_to_json(elements: List(Element(msg)), key: String) { json.preprocessed_array({ use element, index <- list.index_map(elements) let key = key <> "-" <> int.to_string(index) - do_element_to_json(element, key) + element_to_json(element, key) }) } -- cgit v1.2.3