Skip to content

Comments

Publish v1.1.6 fix history state computed#46

Merged
clamstew merged 6 commits intomainfrom
publish-v1.1.5-fix-history-state-computed
Nov 28, 2025
Merged

Publish v1.1.6 fix history state computed#46
clamstew merged 6 commits intomainfrom
publish-v1.1.5-fix-history-state-computed

Conversation

@clamstew
Copy link
Owner

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

AI Optimization Checklist

  • I've run pnpm run ai:sync to verify AI-optimized files are in sync
  • I've generated AI-optimized versions for any new complex files
  • I've reviewed all generated AI-optimized files for accuracy

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

…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 ✅
@clamstew clamstew changed the title Publish v1.1.5 fix history state computed Publish v1.1.6 fix history state computed Nov 28, 2025
@clamstew clamstew self-assigned this Nov 28, 2025
@clamstew clamstew merged commit 399a9b8 into main Nov 28, 2025
2 checks passed
@clamstew clamstew deleted the publish-v1.1.5-fix-history-state-computed branch November 28, 2025 06:13
@clamstew clamstew restored the publish-v1.1.5-fix-history-state-computed branch January 6, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant