|
8 | 8 | getOwner, |
9 | 9 | ownerPath |
10 | 10 | } from "../src/index.js"; |
| 11 | +import { attribution } from "../src/attribution.js"; |
11 | 12 | import { |
12 | 13 | $$component, |
13 | 14 | $$decline, |
@@ -119,6 +120,52 @@ describe("$$component proxy owner paths", () => { |
119 | 120 | expect(inner).toEqual(["<Counter>", "total"]); |
120 | 121 | }); |
121 | 122 |
|
| 123 | + test("the wrapper is nobody's node: the engine records the body's nodes, never the memo", () => { |
| 124 | + const { hot, fireAccept } = createViteHot(); |
| 125 | + const release = attribution.enable({ log: false }); |
| 126 | + const creates: [string, string][] = []; |
| 127 | + const reruns: string[] = []; |
| 128 | + const offCreate = attribution.subscribe("create", e => creates.push([e.nodeName, e.nodeKind])); |
| 129 | + const offRerun = attribution.subscribe("rerun", e => reruns.push(e.nodeName)); |
| 130 | + try { |
| 131 | + const first = executeModule(hot, { |
| 132 | + Counter: { |
| 133 | + impl: () => { |
| 134 | + createMemo(() => 1, { name: "total" })(); |
| 135 | + return null; |
| 136 | + }, |
| 137 | + options: { signature: "sig-a" } |
| 138 | + } |
| 139 | + }); |
| 140 | + render(first.proxies.Counter); |
| 141 | + flush(); |
| 142 | + expect(creates).toEqual([["total", "memo"]]); |
| 143 | + |
| 144 | + // A swap re-runs the wrapper's memo; that run is not a record either — |
| 145 | + // only the new body's nodes are. |
| 146 | + executeModule(hot, { |
| 147 | + Counter: { |
| 148 | + impl: () => { |
| 149 | + createMemo(() => 2, { name: "total2" })(); |
| 150 | + return null; |
| 151 | + }, |
| 152 | + options: { signature: "sig-b" } |
| 153 | + } |
| 154 | + }); |
| 155 | + fireAccept({}); |
| 156 | + flush(); |
| 157 | + expect(creates).toEqual([ |
| 158 | + ["total", "memo"], |
| 159 | + ["total2", "memo"] |
| 160 | + ]); |
| 161 | + expect(reruns).toEqual([]); |
| 162 | + } finally { |
| 163 | + offCreate(); |
| 164 | + offRerun(); |
| 165 | + release(); |
| 166 | + } |
| 167 | + }); |
| 168 | + |
122 | 169 | test("the proxy carries the component's name for an unlabelled createComponent", () => { |
123 | 170 | const { hot } = createViteHot(); |
124 | 171 | const { proxies } = executeModule(hot, { Counter: { impl: () => null } }); |
|
0 commit comments