lustre-labs / lustre

A Gleam web framework for building HTML templates, single page applications, and real-time server components.
https://hexdocs.pm/lustre
MIT License
1.19k stars 76 forks source link

Bug when calling a certain ffi function in ffi.gleam #194

Closed Norlock closed 3 weeks ago

Norlock commented 1 month ago

In the (main) bundled mjs file a function to the ffi will add the following code: (void 0())

code in gleam:

@external(javascript, "./ffi.mjs", "drawLines")
pub fn draw_lines() -> Nil {
  Nil
}

excerpt main mjs file:

function modify_view(model) {
  let try_node_view = (node_idx, row_pos) => {
    return unwrap2(node_view(model, node_idx, row_pos), none3());
  };
  let left_row = (() => {
    let _pipe = model.nodes_left_row;
    let _pipe$1 = map2(
      _pipe,
      (idx) => {
        return try_node_view(idx, new Left());
      }
    );
    return node_views_into_rows(_pipe$1, new Left());
  })();
  let center_row = (() => {
    let _pipe = toList([try_node_view(model.active_node, new Center())]);
    return node_views_into_rows(_pipe, new Center());
  })();
  let right_row = (() => {
    let _pipe = model.nodes_right_row;
    let _pipe$1 = map2(
      _pipe,
      (idx) => {
        return try_node_view(idx, new Right());
      }
    );
    return node_views_into_rows(_pipe$1, new Right());
  })();
  (void 0)();
  log("some ffi log");
  return div(
    toList([class$("write-overview")]),
    toList([
      svg(toList([id("lines-svg")]), toList([])),
      left_row,
      center_row,
      right_row
    ])
  );
}

When I move the exact same code from ffi.gleam to js.gleam it works again. The log function does work.

Info:

Version: gleam 1.5.0

Lustre version:

[dependencies]
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
lustre_http = ">= 0.5.2 and < 1.0.0"
lustre = ">= 4.5.0 and < 5.0.0"
hayleigh-dot-dev commented 1 month ago

Sorry i’m going to need some more to go on than that, what is the gleam code?

hayleigh-dot-dev commented 3 weeks ago

Closing this for now, feel free to re-open if you can provide some more details!