fix: add isValidClassInstance method to detect serialized class instances#27
Closed
fix: add isValidClassInstance method to detect serialized class instances#27
Conversation
…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
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. |
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.
Summary
Fixes the bug where
processorManager.executePreProcessors is not a functionerror occurs when using the StrRay Codex Injection plugin.Root Cause
When the
ProcessorManagerclass instance is stored in theStringRayStateManagerwith 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
Added
isValidClassInstance()method - New method onStringRayStateManagerthat 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.Enhanced logging in
get()- AddedvalueTypeto the log output for debugging purposes.Changes
src/state/state-manager.ts: AddedisValidClassInstance(value, methodName)method and enhanced get() loggingTesting
The fix was validated in the Zigzag project by:
executePreProcessorsmethod exists before using the retrieved objectProcessorManagerinstances instead of trying to reuse serialized onesThis ensures backward compatibility while providing a utility method for consumers to detect invalid class instances.