docs(ct): document class instance serialization limitation#39984
Open
furkankoykiran wants to merge 7 commits intomicrosoft:mainfrom
Open
docs(ct): document class instance serialization limitation#39984furkankoykiran wants to merge 7 commits intomicrosoft:mainfrom
furkankoykiran wants to merge 7 commits intomicrosoft:mainfrom
Conversation
Class instances silently lose their prototype methods when serialized across the Node/browser boundary, leading to confusing runtime errors. This adds a console.warn to detect class instances early and guide users toward plain objects or test stories. Fixes: microsoft#22194
Add explicit documentation about class instances losing prototype methods when passed as props, with before/after code examples. Fixes: microsoft#22194
Verifies that mounting a component with a class instance prop produces a console.warn about prototype method loss. Fixes: microsoft#22194
1 task
Skn0tt
reviewed
Apr 1, 2026
Member
Skn0tt
left a comment
There was a problem hiding this comment.
Thanks for the PR! I worry that the warning will produce a lot of false-positive noise, e.g. for users that make frequent use of DTO-style classes.
class UserDTO {
constructor(readonly name: string) {}
}
await mount(<Button title="test" data-model={new UserDTO("Alice")} />);We don't currently have a good way of exposing a warning just for failing tests. Maybe let's just do the docs for now?
The runtime warning produced false-positive noise for DTO-style classes whose prototype methods are not called in components. Refs microsoft#39984
Test is no longer needed since the runtime warning was removed. Refs microsoft#39984
Replace the separate UserModel code block with a brief inline comment in the existing 'this will not work' block, as suggested by reviewer. Refs microsoft#39984
Contributor
Author
|
Makes sense -- a DTO that just carries data isn't broken by serialization, so warning on every class instance would produce a lot of noise for no real benefit. Removed the runtime warning and its test, kept the docs update, and tightened the example per your suggestion (dropped the separate code block in favor of the inline comment in the existing "this will not work" block). |
Co-authored-by: Simon Knott <info@simonknott.de> Signed-off-by: Furkan Köykıran <furkankoykiran@gmail.com>
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
mount()props, due to Node-to-browser serializationFixes #22194