The registerClass method uses the name of a constructor function to generate a hash key, which is in turn used to encode and decode data for serialization/deserialization. However, that name can change if the script is minified/mangled/obfuscated or otherwise changed.
There are two ways this can go wrong:
-
Minifiers will usually change function names to short strings, often a single letter. This makes it more likely that different classes will have constructor functions with the same name, causing hash collisions.
-
If the client-side script is minified but the server is not, the same class will have different names and therefore different hash keys on the server and the client, causing all incoming serialized objects to be unrecognized.
One solution is to require that all serializable classes/constructors have a unique, static name property/getter. This is not strictly necessary for code that won't be minified, since classes that inherit from other classes should set their own constructor function name, even if the parent class has an explicitly declared name. But it'd be best practice and should be applied to all serializable classes defined in the Lance engine or any other published libraries.
In the meantime, the only workaround I can figure out is to disable renaming functions in minifier settings.
This is related to #82, but distinct. Both need to be fixed separately.
The
registerClassmethod uses the name of a constructor function to generate a hash key, which is in turn used to encode and decode data for serialization/deserialization. However, that name can change if the script is minified/mangled/obfuscated or otherwise changed.There are two ways this can go wrong:
Minifiers will usually change function names to short strings, often a single letter. This makes it more likely that different classes will have constructor functions with the same name, causing hash collisions.
If the client-side script is minified but the server is not, the same class will have different names and therefore different hash keys on the server and the client, causing all incoming serialized objects to be unrecognized.
One solution is to require that all serializable classes/constructors have a unique, static name property/getter. This is not strictly necessary for code that won't be minified, since classes that inherit from other classes should set their own constructor function name, even if the parent class has an explicitly declared name. But it'd be best practice and should be applied to all serializable classes defined in the Lance engine or any other published libraries.
In the meantime, the only workaround I can figure out is to disable renaming functions in minifier settings.
This is related to #82, but distinct. Both need to be fixed separately.