@kudzujs/core 0.8.39 → 0.8.40
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/MIGRATION_ROADMAP.md +1 -1
- package/PERFORMANCE.md +44 -0
- package/README.md +1 -1
- package/RELEASES.md +32 -0
- package/docs/next-architecture/README.md +1 -1
- package/docs/next-architecture/compiler-current-architecture.md +2 -2
- package/docs/next-architecture/large-application-ai-native-roadmap.md +4 -4
- package/docs/next-architecture/versioning.md +2 -1
- package/framework/compiler/effect-analysis.mjs +25 -9
- package/framework/core.mjs +3 -2
- package/package.json +1 -1
package/MIGRATION_ROADMAP.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This document is the source of truth for Kudzu's product direction, architecture invariants, and future development order. Read it before extending React-shaped syntax or browser capabilities.
|
|
4
4
|
|
|
5
|
-
The executable post-`0.8.
|
|
5
|
+
The executable post-`0.8.40` compiler and large-application sequence is maintained in [`docs/next-architecture/large-application-ai-native-roadmap.md`](./docs/next-architecture/large-application-ai-native-roadmap.md). Follow its PR dependencies for implementation work; this document remains authoritative when selecting or accepting a migration capability.
|
|
6
6
|
|
|
7
7
|
[`GOAL_A.md`](./GOAL_A.md) and [`GOAL_B.md`](./GOAL_B.md) are completed capability-validation records. Their commerce and realtime dashboard fixtures prove general lifecycle, navigation, async-workflow, and Worker capabilities; they are not separate product verticals or future priority lists.
|
|
8
8
|
|
package/PERFORMANCE.md
CHANGED
|
@@ -2,6 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
Reproducibility classes: `npm run benchmark`, `npm run benchmark:keyed`, `npm run benchmark:native`, and `npm run benchmark:module-cache` are maintained in this repository; `npm run benchmark:commerce` is a maintained paired runner over the public external storefront; older excluded-workspace sections are historical provenance only and are not current framework rankings.
|
|
4
4
|
|
|
5
|
+
## P1 Property-Level Object-State Effect Dependencies
|
|
6
|
+
|
|
7
|
+
Measured UTC 2026-08-12 on the Intel Core i5-9500 Linux x64 host with 6 physical cores, Node 24.14.0, npm 11.9.0, and Chrome 142.0.7444.175. The baseline was clean tag `v0.8.39` at `090b42124d596260bdd6a0814c014e5b906dc0eb`. The focused implementation and migration checks had SHA-256 `c097c10e786ff5d09537b52384c1bf3d32cb46998ef62125c23dda3355b62277`, produced by:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
sha256sum framework/compiler/effect-analysis.mjs framework/core.mjs test/compiler-passes.test.mjs test/fixtures/zustand-migration/src/Shell.tsx test/framework.test.mjs | sha256sum
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The complete 154-page repository build used one warm-up and 21 alternating clean fresh-process samples. Both targets emit 175 files and byte-identical `kudzu-plan.json` (`be842101f08aab2d8b3af5daa3ed0539a6a08ea8c3cba15cd25f3a36d53ef61f`). The only deploy difference is the updated public explanation in `docs/index.html`: candidate output adds 98 raw bytes and 31 aggregate gzip bytes. Compiler, effect runtime, route JavaScript, and all other artifacts are byte-identical.
|
|
14
|
+
|
|
15
|
+
| Target | Clean build median | Range | Peak RSS median | Deploy raw / gzip bytes |
|
|
16
|
+
|---|---:|---:|---:|---:|
|
|
17
|
+
| `v0.8.39` | 3,753.276 ms | 3,097.211-5,294.316 ms | 356.9 MiB | 3,845,393 / 1,983,262 B |
|
|
18
|
+
| Property dependency candidate | 3,883.841 ms | 3,533.936-4,919.378 ms | 363.7 MiB | 3,845,491 / 1,983,293 B |
|
|
19
|
+
|
|
20
|
+
The candidate unpaired median is 3.48% higher and the round-paired candidate-minus-baseline median is +103.031 ms. Peak RSS is 1.92% higher. Timing ranges overlap substantially and both changes remain below the 5% material-regression threshold, so no material build or memory regression is established.
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
v0.8.39: [5294.316,4885.317,4462.086,3696.012,3105.264,3491.623,3852.100,3414.218,3753.276,3854.507,4311.174,3833.095,3097.211,3669.963,3567.084,3399.614,3626.351,3687.408,3883.556,4104.665,3880.847]
|
|
24
|
+
candidate: [4919.378,4548.065,4236.325,3752.842,3788.156,3738.609,3883.841,4110.706,4055.150,4116.317,3710.973,4016.578,3533.936,3625.603,3670.115,3840.795,4045.689,3988.434,3619.226,3944.068,3760.976]
|
|
25
|
+
paired candidate-baseline: [-374.938,-337.252,-225.761,56.830,682.892,246.986,31.741,696.488,301.874,261.810,-600.201,183.483,436.725,-44.360,103.031,441.181,419.338,301.026,-264.330,-160.597,-119.871]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The tracked runtime matrix then ran one warm-up, seven interleaved clean builds, and seven rotating fresh Chrome profiles for matched Kudzu, React/Vite, Vue/Vite, and Svelte/Vite workloads. Every correctness, accessibility, identity, effect-cleanup, and browser-error gate passed. This matrix uses a primitive effect dependency, so it is broad regression evidence rather than a property-dependency-specific framework claim.
|
|
29
|
+
|
|
30
|
+
| Runtime matrix target | Build median | JS raw / gzip B | Total raw / gzip B | Initial DOM | Effect update + cleanup |
|
|
31
|
+
|---|---:|---:|---:|---:|---:|
|
|
32
|
+
| Kudzu `0.8.39` candidate | 862.432 ms | 33,575 / 12,928 | 212,963 / 49,936 | 363.4 ms | 1.9 ms |
|
|
33
|
+
| React 19.2.8 + Vite 8.1.5 | 498.572 ms | 193,685 / 60,043 | 193,967 / 60,262 | 355.7 ms | 4.4 ms |
|
|
34
|
+
| Vue 3.5.40 + Vite 8.1.5 | 655.787 ms | 64,023 / 24,772 | 64,304 / 24,993 | 283.0 ms | 1.9 ms |
|
|
35
|
+
| Svelte 5.56.7 + Vite 8.1.5 | 907.584 ms | 40,726 / 15,659 | 41,007 / 15,878 | 307.9 ms | 2.5 ms |
|
|
36
|
+
|
|
37
|
+
The tracked six-route commerce sources also completed seven rotating clean builds for Kudzu, React SSR + Vite hydration, Next.js static export, Nuxt generation, and SvelteKit adapter-static. These targets have matched initial content and behavior contracts but materially different architectures.
|
|
38
|
+
|
|
39
|
+
| Commerce target | Build median | Files | HTML raw / gzip B | JS raw / gzip B | Total raw / gzip B |
|
|
40
|
+
|---|---:|---:|---:|---:|---:|
|
|
41
|
+
| Kudzu | 1,062.059 ms | 17 | 17,123 / 5,376 | 18,428 / 8,261 | 37,434 / 14,689 |
|
|
42
|
+
| React 19.2.8 SSR + Vite hydration | 1,020.288 ms | 10 | 9,304 / 4,265 | 198,261 / 61,464 | 209,270 / 66,741 |
|
|
43
|
+
| Next.js 16.2.11 static export | 7,939.352 ms | 74 | 72,890 / 19,860 | 643,484 / 191,844 | 814,186 / 247,612 |
|
|
44
|
+
| Nuxt 4.5.0 generation | 8,566.437 ms | 26 | 17,557 / 7,857 | 191,758 / 70,925 | 215,851 / 82,075 |
|
|
45
|
+
| SvelteKit 2.70.1 static export | 5,778.467 ms | 19 | 15,832 / 6,520 | 85,095 / 33,482 | 102,659 / 41,061 |
|
|
46
|
+
|
|
47
|
+
Kudzu commerce output is 4.54x-16.86x smaller in aggregate gzip than the compared hydrated/client-navigation outputs. React's clean build median is 3.9% lower than Kudzu's on this small fixture; Kudzu builds 5.4x-8.1x faster than the three full static-export frameworks. The full commerce browser command was attempted twice, but both runs timed out in Kudzu's existing in-flight rejection-navigation wait before cross-target browser sampling; no commerce browser timing result is claimed. The complete runtime matrix browser run above passed. Property-path effects reuse existing DerivedIR, source subscriptions, expression evaluation, and `Object.is`; no runtime module or field-signal mechanism was added.
|
|
48
|
+
|
|
5
49
|
## P0.12 Deep RouteIR And CapabilityIR Validation
|
|
6
50
|
|
|
7
51
|
Measured UTC 2026-08-12 on the Intel Core i5-9500 Linux x64 host with 6 physical cores, Node 24.14.0, and npm 11.9.0. The baseline was clean tag `v0.8.38` at `918f721d369fed486c5ff04a7423f79563e1c42e`. The focused implementation files had SHA-256 `f8f58432f264d5df12cadfba07986712cecf148be300b6071c03adaf42fd6594`, produced by:
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Kudzu compiles ordinary React-shaped TypeScript and TSX into complete static HTM
|
|
|
14
14
|
|
|
15
15
|
> Experimental `0.8.x`: the compiler API and supported TSX surface may change.
|
|
16
16
|
|
|
17
|
-
**Latest release: 0.8.
|
|
17
|
+
**Latest release: 0.8.40 - Property-level effect dependencies.** Effects can now depend on direct property paths and immutable primitive locals over ordinary object state while reusing existing DerivedIR and `Object.is` comparison. Read the [release notes](./RELEASES.md#0840---property-level-effect-dependencies), open the [release page](https://github.com/kudzujs/kudzu/releases/tag/v0.8.40), or follow the [architecture packet](./docs/next-architecture/README.md).
|
|
18
18
|
|
|
19
19
|
- [Documentation](https://kudzujs.cloud/docs)
|
|
20
20
|
- [Installation guide](https://kudzujs.cloud/docs#install)
|
package/RELEASES.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Kudzu Releases
|
|
2
2
|
|
|
3
|
+
## 0.8.40 - Property-level effect dependencies
|
|
4
|
+
|
|
5
|
+
Kudzu 0.8.40 starts the large-application foundation sequence by allowing ordinary object state to expose property-level effect dependencies without artificial primitive-state decomposition.
|
|
6
|
+
|
|
7
|
+
### Changed in 0.8.40
|
|
8
|
+
|
|
9
|
+
- Direct property paths over ordinary object state compile to existing tagged DerivedIR.
|
|
10
|
+
- Top-level immutable primitive locals derived from object properties use the same source subscription and expression evaluator.
|
|
11
|
+
- Source object commits schedule dependency comparison, while `Object.is` prevents cleanup and rerun when the selected property value is unchanged.
|
|
12
|
+
- Whole-object, dynamic-property, object-valued, and mixed whole-object/property dependencies remain fail-closed.
|
|
13
|
+
- The Zustand migration fixture proves property updates, equality across enhanced navigation, persistent layout ownership, and removal.
|
|
14
|
+
- No field signal, proxy, component rerender, RouteIR field, or browser runtime module was added.
|
|
15
|
+
|
|
16
|
+
### Performance
|
|
17
|
+
|
|
18
|
+
- Twenty-one alternating clean builds measured `v0.8.39` and candidate medians of 3,753.276 ms and 3,883.841 ms, with a +103.031 ms paired median.
|
|
19
|
+
- Peak RSS medians were 356.9 MiB and 363.7 MiB. Build and memory deltas remain below the 5% material-regression threshold.
|
|
20
|
+
- Both targets emit 175 files and byte-identical `kudzu-plan.json`; only updated docs add 98 raw and 31 aggregate gzip bytes. Runtime and route JavaScript are unchanged.
|
|
21
|
+
- Seven-build/fresh-profile React, Vue, and Svelte runtime comparisons pass. The matched commerce build matrix records Kudzu output at 14,689 aggregate gzip bytes versus 66,741 for React hydration, 247,612 for Next, 82,075 for Nuxt, and 41,061 for SvelteKit.
|
|
22
|
+
|
|
23
|
+
### Validation
|
|
24
|
+
|
|
25
|
+
- `npm run check`, `npm test`, and `npm run test:package` pass with all 205 tests and 155 generated pages.
|
|
26
|
+
- Focused checks cover direct object-property classification, canonical DerivedIR, whole-object/property ambiguity, RouteIR projection, browser equality behavior, and layout lifetime.
|
|
27
|
+
- The next migration-backed investigation is multi-boundary component/prop/callback/ref/context dataflow.
|
|
28
|
+
|
|
29
|
+
### Upgrade
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @kudzujs/core@^0.8.40
|
|
33
|
+
```
|
|
34
|
+
|
|
3
35
|
## 0.8.39 - Fail-closed route contracts
|
|
4
36
|
|
|
5
37
|
Kudzu 0.8.39 completes P0.12 by deeply validating the concrete RouteIR, RouteBuildRecord, and CapabilityIR contracts before artifact selection and browser code generation.
|
|
@@ -11,7 +11,7 @@ The top-level [`GOAL_A.md`](../../GOAL_A.md) and [`GOAL_B.md`](../../GOAL_B.md)
|
|
|
11
11
|
| C: state/resource model | Research only | Reduced fixtures expose a limitation |
|
|
12
12
|
| D: routing compatibility | Current behavior preserved | Revisit only with migration evidence and invariant review |
|
|
13
13
|
|
|
14
|
-
The active post-`0.8.
|
|
14
|
+
The active post-`0.8.40` implementation sequence is [`large-application-ai-native-roadmap.md`](./large-application-ai-native-roadmap.md). P0.12 deep RouteIR and CapabilityIR validation and the first P1 property-level object-state dependency slice are complete; the next migration-backed investigation is multi-boundary component/prop/callback/ref/context dataflow. The plan orders compiler semantic generalization, large-application foundations, compatibility boundaries, AI tooling, and production validation without changing the invariants below.
|
|
15
15
|
|
|
16
16
|
## Required Invariants
|
|
17
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Current Compiler Architecture
|
|
2
2
|
|
|
3
|
-
This maps the current `0.8.
|
|
3
|
+
This maps the current `0.8.40` architecture, built on the completed `0.8.23` Goal A compiler foundation. File and function names are the stable references; line numbers are intentionally omitted because later work may still move code.
|
|
4
4
|
|
|
5
5
|
## Responsibility Map
|
|
6
6
|
|
|
@@ -25,7 +25,7 @@ This maps the current `0.8.39` architecture, built on the completed `0.8.23` Goa
|
|
|
25
25
|
| Source compilation | [`framework/compiler/source-compiler.mjs`](../../framework/compiler/source-compiler.mjs), `compileSource()` | Runs TypeScript with the Kudzu transformer, rejects surviving React/Router references, and returns a JSON-safe project-relative build module, component analysis, ModuleIR, optional handler module, and imported assets without filesystem writes. |
|
|
26
26
|
| Handler/evaluator lowering | [`framework/compiler/handler-lowering.mjs`](../../framework/compiler/handler-lowering.mjs) | Completes source-local callback/binding/list AST rewriting and diagnostics before the JSON-safe IR boundary. |
|
|
27
27
|
| Handler module codegen | [`framework/compiler/handler-codegen.mjs`](../../framework/compiler/handler-codegen.mjs) | Renders finalized ordered imports and concatenates generated module-export source without TypeScript AST or semantic discovery. |
|
|
28
|
-
| Effect analysis | [`framework/compiler/effect-analysis.mjs`](../../framework/compiler/effect-analysis.mjs) | Classifies ordered signal,
|
|
28
|
+
| Effect analysis | [`framework/compiler/effect-analysis.mjs`](../../framework/compiler/effect-analysis.mjs) | Classifies ordered signal, ordinary object-property DerivedIR, and keyed-item dependencies and validates cleanup-owned browser resources before EffectIR registration. Object sources keep one signal subscription while the existing tagged evaluator and `Object.is` compare the selected primitive value. |
|
|
29
29
|
| Worker graph | [`framework/compiler/worker-compiler.mjs`](../../framework/compiler/worker-compiler.mjs) | Returns functional Worker rewrite results and JSON-safe EffectIR edges, validates relative graphs, emits content-hashed ESM, and resolves placeholders only for rendered effects. |
|
|
30
30
|
| Shared path conversion | [`framework/compiler/path-helpers.mjs`](../../framework/compiler/path-helpers.mjs) | Converts project-relative module, browser, asset, and base paths for build and development serving. |
|
|
31
31
|
| Build-time JSX execution | [`framework/core.mjs`](../../framework/core.mjs), `renderPage()` | Executes compiled pages/layouts, allocates deterministic route/layout ownership IDs, emits complete HTML, and returns RouteIR v1 plus capability facts and exact retained handler references. |
|
|
@@ -166,7 +166,7 @@ P0 creates the semantic base required by every later large-application capabilit
|
|
|
166
166
|
| Objective | Required result |
|
|
167
167
|
|---|---|
|
|
168
168
|
| Cross-module component and prop dataflow | Deep composition, callbacks, setters, refs, context, and children retain semantic links without repeated AST inlining |
|
|
169
|
-
| Property-level derived dependencies | Object state
|
|
169
|
+
| Property-level derived dependencies | Object state exposes direct property-path effect dependencies through existing DerivedIR without splitting application state into artificial primitives; multi-boundary propagation remains ordered next |
|
|
170
170
|
| Package-neutral shared state and actions | Existing Zustand support lowers through generic signal/action records; Redux-shaped research has a reusable target |
|
|
171
171
|
| Resource ownership | WebSocket, SSE, subscriptions, timers, observers, Workers, and imperative SDKs can share acquire/owner/dependency/cleanup semantics |
|
|
172
172
|
| Browser-only package modules | Native JS packages may be bundled only into effect/handler/resource chunks without build-time execution |
|
|
@@ -377,8 +377,8 @@ function increment(value) { setCount(value + 1) }; increment(count)
|
|
|
377
377
|
|
|
378
378
|
After the relevant P0 foundations, investigate capabilities in this order:
|
|
379
379
|
|
|
380
|
-
1. Property-level derived dependencies over ordinary object state.
|
|
381
|
-
2. Multi-boundary component/prop/callback/ref/context dataflow.
|
|
380
|
+
1. Property-level derived dependencies over ordinary object state. **Completed in `0.8.40`:** direct property paths and top-level immutable primitive locals over object state reuse tagged DerivedIR, subscribe to the source signal, and compare selected values with `Object.is`; whole-object and dynamic dependencies remain rejected.
|
|
381
|
+
2. Multi-boundary component/prop/callback/ref/context dataflow. **Next.**
|
|
382
382
|
3. Package-neutral shared state/actions and migration of current Zustand internals.
|
|
383
383
|
4. Browser-only package imports in owned effect/resource modules.
|
|
384
384
|
5. ResourceIR from at least two independent WebSocket/SSE/SDK fixtures with the same semantics.
|
|
@@ -480,4 +480,4 @@ The first comparison is Kudzu versus React + Vite using the same agent, model, t
|
|
|
480
480
|
|
|
481
481
|
## Immediate Decision
|
|
482
482
|
|
|
483
|
-
PR 1 through PR 12 are complete. The next migration-backed investigation is **
|
|
483
|
+
PR 1 through PR 12 and the `0.8.40` P1 property-dependency slice are complete. The next migration-backed investigation is **multi-boundary component/prop/callback/ref/context dataflow**. Do not skip directly to a store, resource, router, virtualization, or ecosystem package feature.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Planned Version Sequence
|
|
2
2
|
|
|
3
|
-
This is an execution sequence, not release history. `0.8.16` through `0.8.
|
|
3
|
+
This is an execution sequence, not release history. `0.8.16` through `0.8.40` are completed scopes represented by package/release records.
|
|
4
4
|
|
|
5
5
|
Keep each patch behavior-preserving and independently reviewable. If a boundary proves inseparable, revise this plan before combining releases; do not silently broaden a patch.
|
|
6
6
|
|
|
@@ -30,6 +30,7 @@ Keep each patch behavior-preserving and independently reviewable. If a boundary
|
|
|
30
30
|
| `0.8.37` | Unify ModuleIR and ComponentAnalysis references through deterministic source-local slots and stable symbols. | Every handler, binding, derived, effect, keyed, specialization, state, ref, capture, and import edge validates before build-module generation. |
|
|
31
31
|
| `0.8.38` | Replace serialized route artifact discovery with validated RouteBuildRecord edges. | Handler, effect, Worker, CSS, package-client, and chunk retention is structural while deploy files, bytes, plans, and browser behavior remain unchanged. |
|
|
32
32
|
| `0.8.39` | Deeply validate concrete RouteIR, RouteBuildRecord, and CapabilityIR contracts. | Invalid state, command, effect, binding, condition, list, ownership, capability, and JSON references fail before codegen without changing deploy output. |
|
|
33
|
+
| `0.8.40` | Add property-level derived effect dependencies over ordinary object state. | Direct property paths and immutable primitive locals reuse existing DerivedIR and `Object.is`; whole-object/dynamic dependencies fail, runtime JavaScript is unchanged, and measured build/RSS changes remain below 5%. |
|
|
33
34
|
|
|
34
35
|
## Sequence Rules
|
|
35
36
|
|
|
@@ -20,9 +20,6 @@ export function analyzeEffectDependencies({ dependencies, node, listEffect, keye
|
|
|
20
20
|
ordinaryDependencies.push(dependency)
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
const invalidDependency = ordinaryDependencies.find(dependency => !ts.isIdentifier(dependency))
|
|
24
|
-
if (invalidDependency) fail(invalidDependency, "useEffect() dependencies must be direct state or runtime parameter identifiers")
|
|
25
|
-
|
|
26
23
|
const entries = []
|
|
27
24
|
const dependencyStates = new Map()
|
|
28
25
|
const substitutions = new Map()
|
|
@@ -30,28 +27,36 @@ export function analyzeEffectDependencies({ dependencies, node, listEffect, keye
|
|
|
30
27
|
let hasDerived = false
|
|
31
28
|
const stateNames = new Set(setters.values())
|
|
32
29
|
for (const dependency of ordinaryDependencies) {
|
|
33
|
-
const
|
|
30
|
+
const direct = ts.isIdentifier(dependency)
|
|
31
|
+
if (!direct && !statePropertyDependency(dependency, stateNames)) fail(dependency, "useEffect() dependencies must be direct state or runtime parameter identifiers or property reads")
|
|
32
|
+
const declarations = direct ? localDeclarations?.get(dependency.text) : undefined
|
|
34
33
|
const initializer = declarations?.length === 1 ? declarations[0].initializer : undefined
|
|
35
34
|
const indexedInitializer = initializer && bindingIndex?.hasNode(initializer) ? bindingIndex : undefined
|
|
36
35
|
const directAlias = initializer && ts.isIdentifier(unwrapExpression(initializer)) && stateNames.has(unwrapExpression(initializer).text) && (!indexedInitializer || ["capture", "unresolved"].includes(indexedInitializer.resolveReference(unwrapExpression(initializer), initializer)?.kind))
|
|
37
|
-
const
|
|
36
|
+
const expressionSource = initializer && !directAlias ? initializer : direct ? undefined : dependency
|
|
37
|
+
let derivedStates = expressionSource ? referencedStateNames(expressionSource, setters, expressionSource, bindingIndex) : new Set()
|
|
38
|
+
if (!derivedStates.size && expressionSource) derivedStates = referencedStateNames(expressionSource, setters, expressionSource)
|
|
38
39
|
if (derivedStates.size) {
|
|
39
40
|
const usedStates = new Set()
|
|
40
|
-
const expression = collectionExpression(
|
|
41
|
-
if (!usedStates.size) fail(dependency, `useEffect() derived dependency
|
|
42
|
-
entries.push({ kind: "derived", name: dependency.text, expression, states: usedStates, source:
|
|
41
|
+
const expression = collectionExpression(expressionSource, { fail, stateNames, selectorStates: usedStates })
|
|
42
|
+
if (!usedStates.size) fail(dependency, `useEffect() derived dependency must read direct state`)
|
|
43
|
+
entries.push({ kind: "derived", name: direct ? dependency.text : dependency.getText(), expression, states: usedStates, source: expressionSource })
|
|
43
44
|
for (const name of usedStates) {
|
|
44
45
|
subscriptions.push(factory.createIdentifier(name))
|
|
45
46
|
dependencyStates.set(name, factory.createIdentifier(name))
|
|
46
47
|
}
|
|
47
|
-
substitutions.set(dependency.text, initializer)
|
|
48
|
+
if (initializer) substitutions.set(dependency.text, initializer)
|
|
48
49
|
hasDerived = true
|
|
49
50
|
} else {
|
|
51
|
+
if (!direct) fail(dependency, "useEffect() dependencies must be direct state or runtime parameter identifiers or property reads")
|
|
50
52
|
subscriptions.push(dependency)
|
|
51
53
|
entries.push({ kind: "signal", name: dependency.text })
|
|
52
54
|
dependencyStates.set(dependency.text, dependency)
|
|
53
55
|
}
|
|
54
56
|
}
|
|
57
|
+
const derivedSourceNames = new Set(entries.filter(entry => entry.kind === "derived").flatMap(entry => [...entry.states]))
|
|
58
|
+
const ambiguous = entries.find(entry => entry.kind === "signal" && derivedSourceNames.has(entry.name))
|
|
59
|
+
if (ambiguous) fail(ordinaryDependencies[entries.indexOf(ambiguous)], `useEffect() cannot mix whole-object and property dependencies for state ${JSON.stringify(ambiguous.name)}`)
|
|
55
60
|
if (!hasDerived) dependencyStates.clear()
|
|
56
61
|
return { dependencyItem, itemDependencies, ordinaryDependencies, entries, dependencyStates, substitutions, subscriptions, hasDerived }
|
|
57
62
|
}
|
|
@@ -91,3 +96,14 @@ function directProperty(expression, objectName) {
|
|
|
91
96
|
const value = unwrapExpression(expression)
|
|
92
97
|
return ts.isPropertyAccessExpression(value) && ts.isIdentifier(value.expression) && value.expression.text === objectName ? value.name.text : undefined
|
|
93
98
|
}
|
|
99
|
+
|
|
100
|
+
function statePropertyDependency(expression, stateNames) {
|
|
101
|
+
let value = unwrapExpression(expression)
|
|
102
|
+
let property = false
|
|
103
|
+
while (ts.isPropertyAccessExpression(value) || ts.isElementAccessExpression(value)) {
|
|
104
|
+
if (ts.isElementAccessExpression(value) && !ts.isStringLiteral(value.argumentExpression) && !ts.isNumericLiteral(value.argumentExpression)) return false
|
|
105
|
+
property = true
|
|
106
|
+
value = unwrapExpression(value.expression)
|
|
107
|
+
}
|
|
108
|
+
return property && ts.isIdentifier(value) && stateNames.has(value.text)
|
|
109
|
+
}
|
package/framework/core.mjs
CHANGED
|
@@ -174,12 +174,13 @@ export function useEffect(callback, dependencies, module, handler, states, scope
|
|
|
174
174
|
if (!renderContext) throw new Error("useEffect() can only run while rendering a Kudzu component")
|
|
175
175
|
if (typeof callback !== "function" || !Array.isArray(dependencies) || !module || !handler) throw new Error("useEffect() must be compiled with a literal dependency array")
|
|
176
176
|
if (itemDependencies.length && !renderContext.listDepth) throw new Error(`${source} useEffect() item-property dependencies are only supported in direct keyed row components`)
|
|
177
|
+
const derivedSources = new Set(dependencyStates.map(([, dependency]) => dependency))
|
|
177
178
|
const dependencyIds = [...new Set(dependencies.map(dependency => {
|
|
178
|
-
if (!dependency?.[signalMarker] || !validEffectDependency(dependency.value)) throw new Error(`${source} useEffect() dependencies must be primitive Kudzu state or runtime parameter identifiers`)
|
|
179
|
+
if (!dependency?.[signalMarker] || !derivedSources.has(dependency) && !validEffectDependency(dependency.value)) throw new Error(`${source} useEffect() dependencies must be primitive Kudzu state or runtime parameter identifiers`)
|
|
179
180
|
return dependency.id
|
|
180
181
|
}))]
|
|
181
182
|
const dependencyStateIds = Object.fromEntries(dependencyStates.map(([name, dependency]) => {
|
|
182
|
-
if (!dependency?.[signalMarker]
|
|
183
|
+
if (!dependency?.[signalMarker]) throw new Error(`${source} useEffect() derived dependency state ${JSON.stringify(name)} must be Kudzu state`)
|
|
183
184
|
return [name, dependency.id]
|
|
184
185
|
}))
|
|
185
186
|
let owner
|