Skip to content
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

Filtered fields not listening bug #28

Closed
elfwy-uwu opened this issue Dec 12, 2023 · 3 comments
Closed

Filtered fields not listening bug #28

elfwy-uwu opened this issue Dec 12, 2023 · 3 comments

Comments

@elfwy-uwu
Copy link

In case client gets server state with filtered field for the first time (during initialization process in function 'registerCallbacksOnStructure'), and then gets the same unfiltered field, this will throw an error:

f3-ab1a-993d129b22fc:132 Uncaught TypeError: Cannot read properties of undefined (reading 'onChange')
    at registerCallbacksOnStructure (7794a227-3adc-45f3-ab1a-993d129b22fc:132:41)
    at onItemAdd (7794a227-3adc-45f3-ab1a-993d129b22fc:162:17)
    at 7794a227-3adc-45f3-ab1a-993d129b22fc:98:21
    at c8bbf03f-44cd-4da9-9bed-30017196fd2f:4176:155
    at Array.forEach (<anonymous>)
    at _loop_2 (c8bbf03f-44cd-4da9-9bed-30017196fd2f:4176:110)
    at Schema._triggerChanges (c8bbf03f-44cd-4da9-9bed-30017196fd2f:4204:21)
    at Schema.decode (c8bbf03f-44cd-4da9-9bed-30017196fd2f:3746:22)
    at SchemaSerializer.patch (c8bbf03f-44cd-4da9-9bed-30017196fd2f:5167:31)
    at Room.patch (c8bbf03f-44cd-4da9-9bed-30017196fd2f:4613:29)
registerCallbac

This prevents filtered fields from listening and breaks registerCallbacksOnStructure loop chain resulting in even existing fields to fail listening.

@elfwy-uwu
Copy link
Author

The only workaround i found for now is using @filterChildren instead of filter for maps, arrays, collections, it will create empty fields which are fluiding the data but at least it's working. This doesn't apply to direct schema objects as using filterChildren will not work:
@filterChildren: field 'field' can't have children. Ignoring filter.

@elfwy-uwu
Copy link
Author

This seem to be the same case with colyseus/schema#155 where listener is not initialized because it recieves an undefined value instead of some object to listen for.

@endel
Copy link
Member

endel commented Dec 18, 2023

Hi @elfwy-uwu, the original issue you reported (Uncaught TypeError: Cannot read properties of undefined (reading 'onChange')) is due to the C3 SDK expecting to listen for additions on the array, but the array was not present (it was filtered out by @filter()). By using @filterChildren() the SDK can listen to additions to this array.

As discussed on Discord, filters are experimental, and it is not planned to have a fix for this issue at this time. The plan is to introduce a different "data ownership" model next year, and deprecate the filters 🤞

As you suggested, here's a thread about the known issues with filters 🙌 colyseus/schema#163

@endel endel closed this as completed Dec 18, 2023
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

No branches or pull requests

2 participants