aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2024-06-11 18:23:49 +0100
committerHayleigh Thompson <me@hayleigh.dev>2024-06-11 18:24:57 +0100
commit6e3e2848d3d1c2e719ba0e42b2634688ca5fb5df (patch)
tree7d2a51aa5770bb0da02b5a79af9cef8a1a128aa2
parent044ebd053d484827ec58a707d80fda9952966fce (diff)
downloadlustre-6e3e2848d3d1c2e719ba0e42b2634688ca5fb5df.tar.gz
lustre-6e3e2848d3d1c2e719ba0e42b2634688ca5fb5df.zip
:bug: Fixed a bug with incorrect keys produced in server component diffs.
-rw-r--r--src/lustre/internals/patch.gleam8
-rw-r--r--src/lustre/internals/vdom.gleam10
2 files changed, 5 insertions, 13 deletions
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)
})
}