Skip to content

Improve handling of logging with proxies #15478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

colin-grant-work
Copy link
Contributor

What it does

packr will attempt to use toJSON to serialize an object if sees that toJSON is defined. That means that if an object is logged that includes a reference to an RPC proxy, packr will attempt to call toJSON, and a type error will be logged if the remote target does not implement toJSON (even if it does, packr isn't expecting a Promise!). This PR returns undefined when toJSON is requested from a proxy to prevent packr from attempting to use that method to serialize the object.

How to test

  1. Attempt to log an object with a reference to a proxy (e.g. the FileService)
  2. Observe that the log appears successfully on the frontend.
  3. Observe that no error is thrown indicating that this.target[method] is not a function

The log won't appear on the backend because the object couldn't be serialized, but that is the usual behavior when logging anything that doesn't serialize cleanly.

Follow-ups

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Note

Since toJSON is JS API, proxies generally shouldn't implement it, and I don't see any cases where it is included in an interface in the repo. But an adopter could have defined that method in something they proxy, and it would now fail.

Attribution

Review checklist

Reminder for reviewers

@github-project-automation github-project-automation bot moved this to Waiting on reviewers in PR Backlog Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Waiting on reviewers
Development

Successfully merging this pull request may close these issues.

1 participant