Skip to content

docs(ct): document class instance serialization limitation#39984

Open
furkankoykiran wants to merge 7 commits intomicrosoft:mainfrom
furkankoykiran:fix-22194
Open

docs(ct): document class instance serialization limitation#39984
furkankoykiran wants to merge 7 commits intomicrosoft:mainfrom
furkankoykiran:fix-22194

Conversation

@furkankoykiran
Copy link
Copy Markdown
Contributor

@furkankoykiran furkankoykiran commented Apr 1, 2026

Summary

  • Document that class instances lose their prototype methods when passed as mount() props, due to Node-to-browser serialization

Fixes #22194

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
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@furkankoykiran
Copy link
Copy Markdown
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).

@furkankoykiran furkankoykiran requested a review from Skn0tt April 1, 2026 13:55
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Co-authored-by: Simon Knott <info@simonknott.de>
Signed-off-by: Furkan Köykıran <furkankoykiran@gmail.com>
@furkankoykiran furkankoykiran changed the title fix(ct): warn when class instances are passed as mount() props docs(ct): document class instance serialization limitation Apr 1, 2026
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.

[BUG] Objects passed in as props lose their functions.

2 participants