swift-rust 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,9 +45,17 @@
45
45
  }, 1800);
46
46
  }
47
47
 
48
- es.addEventListener("change", function (e) {
48
+ // The server sends *unnamed* SSE messages whose payload is an envelope:
49
+ // data: {"event":"change","data":{"type":"reload",...}}
50
+ // An unnamed SSE message fires the browser's default "message" event — NOT a
51
+ // named "change" event. Listening only on addEventListener("change") meant the
52
+ // handler never fired, so the browser never reloaded and you had to refresh by
53
+ // hand. We listen on "message" (and "change", for forward-compat) and unwrap
54
+ // the envelope, tolerating both the enveloped and flat payload shapes.
55
+ function handlePayload(raw) {
49
56
  try {
50
- var data = JSON.parse(e.data);
57
+ var msg = JSON.parse(raw);
58
+ var data = msg && msg.event && msg.data ? msg.data : msg;
51
59
  if (data.type === "reload") {
52
60
  showToast("↻ Reloading…");
53
61
  setTimeout(function () { location.reload(); }, 100);
@@ -64,7 +72,9 @@
64
72
  } catch (err) {
65
73
  console.error("[swift-rust] bad HMR payload", err);
66
74
  }
67
- });
75
+ }
76
+ es.addEventListener("message", function (e) { handlePayload(e.data); });
77
+ es.addEventListener("change", function (e) { handlePayload(e.data); });
68
78
 
69
79
  es.addEventListener("open", function () {
70
80
  if (window.__sr_setStatus) window.__sr_setStatus(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swift-rust",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "The full-stack React framework powered with Rust + Bun. TSX-first, Rust rendering, 10x faster than Next.js, single binary deploy.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://swift-rust.dev",