Skip to content

Conversation

@christian-byrne
Copy link
Contributor

@christian-byrne christian-byrne commented Jul 24, 2025

Summary

Removes unnecessary JSON fallback logic from cloneObject() since structuredClone is already used extensively throughout the codebase (10+ locations). The fallback was originally added for compatibility, but analysis shows it's no longer needed.

Why This Change is Safe

  • Proven Stability: structuredClone already used in critical paths without issues
  • Superior Functionality: Handles circular references, preserves types (Date, RegExp, undefined)
  • Modern Baseline: 93.81% browser support, standard since March 2022
  • All Tests Pass: 277 tests including comprehensive edge case coverage

Why It Wasn't Done Earlier

structuredClone only became baseline supported in March 2022. The codebase has been gradually migrating to it, with cloneObject() being one of the last holdouts due to conservative timing.

Changes

  • Simplified cloneObject() to use structuredClone() directly
  • Removed try/catch fallback logic and related error handling
  • Streamlined test suite to match simplified implementation

Fixes Comfy-Org/ComfyUI_frontend#4696

…r object cloning

- Use modern structuredClone() API when available for deep cloning
- Maintains fallback to JSON method for compatibility
- Fixes circular reference crashes that previously threw errors
- Preserves type fidelity (Date, RegExp, undefined values)
- Performance neutral to positive due to native implementation
- Add comprehensive test suite covering all edge cases

Fixes #1157
Since structuredClone is already used extensively throughout the codebase
(20+ places), there's no need for JSON fallback. Simplifies implementation
and removes redundant error handling.

- Removed try/catch fallback logic from cloneObject()
- Simplified test suite to match streamlined implementation
- All 277 tests passing

Fixes #1157
Copy link
Contributor

@webfiltered webfiltered left a comment

Choose a reason for hiding this comment

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

In case you missed it during the meeting - you cannot simply drop this in as a replacement and expect it to work. It will break custom nodes, even if the frontend is fixed.

What is the tangible benefit of this disruption?

@christian-byrne
Copy link
Contributor Author

Can you explain why this breaks custom nodes?

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.

[Enhancement] Replace JSON.parse(JSON.stringify()) with structuredClone() for object cloning

3 participants