Publish v1.1.6 fix history state computed#46
Merged
Conversation
…time-travel This documents a discovered edge case where computed properties become undefined after using history() to time-travel. Includes: - Problem description and reproduction steps - Current workaround (calculate from source data) - Four proposed solutions with pros/cons - Implementation plan for recommended solution (Option 1) Discovered while building todo app example with time-travel debugging.
FIXES: Computed properties becoming undefined after history goBack/forward/travelTo Implementation: - Added computed-registry module to track computed definitions per store - Registry stores computed values indexed by history position - History class now re-applies computed definitions after state restoration - setTrap updated to allow re-assignment of computed functions How it works: 1. When user assigns computed to store: registerComputedDefinition() called 2. History tracks current index: setStoreHistoryIndex() updates registry 3. On time-travel: restoreComputedProperties() re-applies correct definitions 4. Versioned tracking ensures correct computed at each history index Tests: - Added computed-history-integration.test.ts with 5 test cases - Basic restoration after goBack/forward - Multiple computed properties - Nested computed (computed depending on computed) - Array methods on restored computed arrays All 356 tests pass ✅
- Added `computed-registry.ts` to track computed definitions per store. - Updated `set.ts` to register computed on assignment. - Modified `core.ts` to re-apply computed properties after time-travel. - Enhanced tests in `computed-history-integration.test.ts` with 5 new cases covering restoration scenarios. This implementation addresses the issue of computed properties becoming undefined during history navigation.
MAJOR IMPROVEMENT: Nested computed properties (like store.stats.total) now survive history time-travel! Changes: - Added dynamic path tracking for nested objects via WeakMap - Nested proxy set trap now correctly builds full paths (e.g., 'stats.total') - History restoration uses setNestedValue() for nested computed paths - Nested computed properties are auto-invoked when accessed - Fixed 'window is not defined' error in Node.js environment Before: appState.stats.total = computed(() => appState.todos.length); appHistory.back(); console.log(appState.stats.total); // undefined ❌ After: appState.stats.total = computed(() => appState.todos.length); appHistory.back(); console.log(appState.stats.total); // Correct value! ✅ All 358 tests pass ✅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Please include a summary of the changes and which issue is fixed. Please also include relevant motivation and context.
Fixes # (issue)
Type of change
AI Optimization Checklist
pnpm run ai:syncto verify AI-optimized files are in syncHow Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
Checklist: