[FIX] Fix nested array isolation in Observer constructor#58
Merged
willeastcott merged 1 commit intomainfrom Jan 10, 2026
Merged
[FIX] Fix nested array isolation in Observer constructor#58willeastcott merged 1 commit intomainfrom
willeastcott merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug where nested arrays were not properly isolated in the Observer constructor, causing issues with real-time collaboration via ShareDB. When source data was modified externally, the Observer's internal data was inadvertently modified as well, preventing change events from firing correctly.
Changes:
- Added
deepCopyArray()utility function to recursively copy nested arrays - Fixed line 205 in
_prepare()method to usedeepCopyArray()instead of the buggy.slice(0)call - Added comprehensive test coverage for nested array isolation scenarios
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/utils.ts | Added deepCopyArray() utility function with proper documentation for deep copying nested arrays |
| src/observer.ts | Fixed nested array isolation bug in _prepare() method by using deepCopyArray() instead of discarding .slice(0) result |
| test/observer.test.mjs | Added comprehensive test suite covering nested array isolation, including the exact bug scenario from issue #684 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
slimbuck
approved these changes
Jan 10, 2026
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.
Fixes playcanvas/editor#684
Overview
The Observer class was not properly isolating nested arrays from source data, causing issues when the source data was modified externally (e.g., by ShareDB during real-time collaboration).
The Problem
When creating an Observer from data containing nested arrays (like
[[1,2,3], [4,5,6]]), the inner arrays were not being copied - only the outer array was shallow copied. This meant the Observer and the source data shared references to the same inner arrays.In the Editor, this caused script attributes with array types (e.g.,
vec3[]) to fail live-updating in the Launch tab:observer.set()was called, the value was already the same, so no*:setevent firedThe Fix
Added
deepCopyArray()utility function inutils.ts(alongside existingarrayEquals)Fixed line 205 in
_prepare()which was calling.slice(0)but discarding the result:// Before (bug)
target._data[key][i].slice(0);
// After (fixed)
target._data[key][i] = deepCopyArray(target._data[key][i]);
3 unit tests have been added. All fail without the fix but now pass.
The original Editor issue is confirmed fixed.