mithril-lynx 0.0.3 → 0.0.5

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mithril-lynx",
3
- "version": "0.0.3",
4
- "description": "Mithril.js rendered through Lynx's Element PAPI — a contract-complete port of mithril/render/render.js@2.3.8 to the Lynx main thread, packaged as a reusable framework.",
3
+ "version": "0.0.5",
4
+ "description": "Mithril.js rendered through Lynx's Element PAPI \u2014 a contract-complete port of mithril/render/render.js@2.3.8 to the Lynx main thread, packaged as a reusable framework.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "repository": {
package/plugin.js CHANGED
@@ -35,6 +35,28 @@ function findSibling(dir, candidates) {
35
35
  return null;
36
36
  }
37
37
 
38
+ /**
39
+ * Walks up from a resolved file to the root of the package that owns it,
40
+ * verified by name rather than assumed from the layout — this package's
41
+ * exports map deliberately doesn't expose ./package.json, so the usual
42
+ * require.resolve("<pkg>/package.json") trick isn't available here.
43
+ */
44
+ function packageRootOf(resolvedFile) {
45
+ let dir = path.dirname(resolvedFile);
46
+ for (let i = 0; i < 10; i++) {
47
+ try {
48
+ const pkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
49
+ if (pkg.name === "mithril-lynx") return dir;
50
+ } catch {
51
+ // keep walking
52
+ }
53
+ const parent = path.dirname(dir);
54
+ if (parent === dir) break;
55
+ dir = parent;
56
+ }
57
+ return null;
58
+ }
59
+
38
60
  export function pluginMithrilLynx(options = {}) {
39
61
  const targetSdkVersion = options.targetSdkVersion ?? "3.5";
40
62
 
@@ -69,6 +91,34 @@ export function pluginMithrilLynx(options = {}) {
69
91
  // leave resolution as-is rather than guessing.
70
92
  }
71
93
 
94
+ // Same class of problem, worse symptom: mithril-lynx itself keeps
95
+ // per-app state in module-level variables — the shim's rootWrapper/
96
+ // redraw/runRender, main-thread.js's latestData and its cross-thread
97
+ // handler maps, background.js's mirror of those. Two physical copies
98
+ // means two disconnected renderers: the app renders through one, and
99
+ // any LIBRARY that depends on mithril-lynx (a component library, say,
100
+ // resolving its own nested copy once linked) calls shim.redraw() on
101
+ // the other — whose `redraw` is still null. That's a silent no-op:
102
+ // no error, nothing logged, components simply never update. Confirmed
103
+ // on real hardware 2026-09-11 while building mithril-lynx-ui, where
104
+ // it read as "the animation just doesn't run".
105
+ try {
106
+ const appRequire = createRequire(path.join(process.cwd(), "package.json"));
107
+ const selfDir = packageRootOf(appRequire.resolve("mithril-lynx"));
108
+ if (selfDir != null) {
109
+ // The bare specifier has to point at the entry FILE: aliasing it
110
+ // to the directory would bypass this package's own exports map
111
+ // (which has no "main" to fall back on) and fail to resolve.
112
+ // The prefix alias then keeps subpaths — "mithril-lynx/main-thread"
113
+ // and friends, which hold state of their own — on that same copy.
114
+ chain.resolve.alias.set("mithril-lynx$", path.join(selfDir, "src", "lynx-mithril-shim.js"));
115
+ chain.resolve.alias.set("mithril-lynx", selfDir);
116
+ }
117
+ } catch {
118
+ // App doesn't resolve mithril-lynx from its own root (it's being
119
+ // consumed some other way) — leave resolution alone.
120
+ }
121
+
72
122
  const rawEntries = Object.entries(chain.entryPoints.entries() ?? {});
73
123
  chain.entryPoints.clear();
74
124
 
@@ -696,23 +696,41 @@ function factory() {
696
696
 
697
697
  function initComponent(vnode, hooks) {
698
698
  var sentinel
699
- if (typeof vnode.tag.view === "function") {
699
+ var classStyle = typeof vnode.tag.view !== "function"
700
+ if (!classStyle) {
700
701
  vnode.state = Object.create(vnode.tag)
701
702
  sentinel = vnode.state.view
702
- if (sentinel.$$reentrantLock$$ != null) return
703
- sentinel.$$reentrantLock$$ = true
704
703
  } else {
705
- vnode.state = void 0
706
704
  sentinel = vnode.tag
707
- if (sentinel.$$reentrantLock$$ != null) return
708
- sentinel.$$reentrantLock$$ = true
709
- vnode.state = (vnode.tag.prototype != null && typeof vnode.tag.prototype.view === "function") ? new vnode.tag(vnode) : vnode.tag(vnode)
710
705
  }
711
- initLifecycle(vnode.state, vnode, hooks)
712
- if (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)
713
- vnode.instance = Vnode.normalize(callHook.call(vnode.state.view, vnode))
714
- if (vnode.instance === vnode) throw Error("A view cannot return the vnode it received as argument")
715
- sentinel.$$reentrantLock$$ = null
706
+ if (sentinel.$$reentrantLock$$ != null) return
707
+ sentinel.$$reentrantLock$$ = true
708
+ // The lock above is stored on `sentinel` — the component's OWN shared
709
+ // view function (or, for class-style components, the tag itself), NOT
710
+ // on this vnode instance — so it's shared by EVERY use of this
711
+ // component anywhere in the app. Without the try/finally below, a
712
+ // view() (or, for a class-style component, its CONSTRUCTOR) that
713
+ // throws on a component's first render (e.g. a fail-loudly validation
714
+ // error) skips the `sentinel.$$reentrantLock$$ = null` reset entirely,
715
+ // leaving that lock stuck at `true` forever. Every later attempt to
716
+ // create that SAME component type — anywhere, not just the one
717
+ // instance that threw — then silently no-ops right here
718
+ // (`if (sentinel.$$reentrantLock$$ != null) return`): no render, no
719
+ // error, nothing. Found via mithril-lynx-ui's own test suite: a
720
+ // component whose view() deliberately throws to validate a prop,
721
+ // exercised in one test, made every SUBSEQUENT test mounting that
722
+ // same component silently render nothing, no matter how unrelated.
723
+ try {
724
+ if (classStyle) {
725
+ vnode.state = (vnode.tag.prototype != null && typeof vnode.tag.prototype.view === "function") ? new vnode.tag(vnode) : vnode.tag(vnode)
726
+ }
727
+ initLifecycle(vnode.state, vnode, hooks)
728
+ if (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)
729
+ vnode.instance = Vnode.normalize(callHook.call(vnode.state.view, vnode))
730
+ if (vnode.instance === vnode) throw Error("A view cannot return the vnode it received as argument")
731
+ } finally {
732
+ sentinel.$$reentrantLock$$ = null
733
+ }
716
734
  }
717
735
 
718
736
  function createComponent(parent, vnode, hooks, ns, nextSibling) {