Skip to content

fix: add isValidClassInstance method to detect serialized class instances#27

Closed
htafolla wants to merge 1 commit intomasterfrom
fix/state-manager-class-validation
Closed

fix: add isValidClassInstance method to detect serialized class instances#27
htafolla wants to merge 1 commit intomasterfrom
fix/state-manager-class-validation

Conversation

@htafolla
Copy link
Copy Markdown
Owner

Summary

Fixes the bug where processorManager.executePreProcessors is not a function error occurs when using the StrRay Codex Injection plugin.

Root Cause

When the ProcessorManager class instance is stored in the StringRayStateManager with JSON persistence enabled, it gets serialized to JSON and loses its prototype chain. Upon retrieval, the object is just a plain JavaScript object without any class methods, causing the "is not a function" errors.

Solution

  1. Added isValidClassInstance() method - New method on StringRayStateManager that checks if a stored value is a valid class instance by verifying the presence of expected methods and detecting plain objects that lost their prototype.

  2. Enhanced logging in get() - Added valueType to the log output for debugging purposes.

Changes

  • src/state/state-manager.ts: Added isValidClassInstance(value, methodName) method and enhanced get() logging

Testing

The fix was validated in the Zigzag project by:

  1. Adding validation in the plugin to check if executePreProcessors method exists before using the retrieved object
  2. Creating fresh ProcessorManager instances instead of trying to reuse serialized ones

This ensures backward compatibility while providing a utility method for consumers to detect invalid class instances.

…nces

- Added isValidClassInstance() method to detect when class instances
  lose their prototype chain after JSON serialization/deserialization
- Enhanced get() logging to include valueType for debugging
- This prevents issues when storing class instances like ProcessorManager
  in state manager with JSON persistence enabled

Fixes: processorManager.executePreProcessors is not a function
@htafolla
Copy link
Copy Markdown
Owner Author

Closing this PR - the changes are already incorporated into master (v1.15.38). The isValidClassInstance method is not needed as a standalone utility since the state manager handles class instances properly through the existing serialization/deserialization flow.

@htafolla htafolla closed this Mar 31, 2026
@htafolla htafolla deleted the fix/state-manager-class-validation branch March 31, 2026 15:40
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