|
| 1 | +/** |
| 2 | + * #3133: `flattenArray` must OR its `needsUnwrap` flag with a nested call's |
| 3 | + * result, not overwrite it. Under `doNotUnwrap`, a function child (a |
| 4 | + * `<For>`/`<Repeat>`/memo accessor) followed at the same level by an array |
| 5 | + * child containing no functions (a fragment) reset the flag, so `flatten` |
| 6 | + * returned the plain results array with the raw accessor still inside it |
| 7 | + * instead of the resolving wrapper. `@solidjs/web` masked this with its |
| 8 | + * insertExpression function branch; universal renderers passed the raw memo |
| 9 | + * to the host's insertNode and crashed. |
| 10 | + */ |
| 11 | +import { describe, expect, it } from "vitest"; |
| 12 | +import { createMemo, createRoot, flatten } from "../src/index.js"; |
| 13 | + |
| 14 | +const OPTS = { skipNonRendered: true, doNotUnwrap: true }; |
| 15 | + |
| 16 | +describe("#3133: flatten needsUnwrap under doNotUnwrap", () => { |
| 17 | + it("keeps the wrapper when a function-free fragment follows an accessor", () => { |
| 18 | + createRoot(() => { |
| 19 | + const accessor = createMemo(() => "from memo"); |
| 20 | + const out = flatten([accessor, ["a", "b"]], OPTS); |
| 21 | + expect(typeof out).toBe("function"); |
| 22 | + expect(out()).toEqual(["from memo", "a", "b"]); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + it("keeps the wrapper when the accessor is inside an earlier fragment", () => { |
| 27 | + createRoot(() => { |
| 28 | + const accessor = createMemo(() => "nested"); |
| 29 | + const out = flatten([[accessor], ["plain"]], OPTS); |
| 30 | + expect(typeof out).toBe("function"); |
| 31 | + expect(out()).toEqual(["nested", "plain"]); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + it("still returns a plain array when nothing needs unwrapping", () => { |
| 36 | + const out = flatten(["a", ["b", "c"]], OPTS); |
| 37 | + expect(Array.isArray(out)).toBe(true); |
| 38 | + expect(out).toEqual(["a", "b", "c"]); |
| 39 | + }); |
| 40 | +}); |
0 commit comments