-
-
Notifications
You must be signed in to change notification settings - Fork 592
Server does not sync state with clients on the latest version #510
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
Comments
Hi @jog1t, Interesting find. It seems that class State extends Schema {
number = 0;
property = "";
}
defineTypes(State, {
property: "string",
number: "number"
}); I've just tried commenting out the property initializer and then your example works: (See sandbox link) class State extends Schema {
// number = 0;
// property = "";
}
defineTypes(State, {
property: "string",
number: "number"
}); For TypeScript this is not an issue. We need to investigate why this is happening, if you have any clues, I highly appreciate it! |
@endel thanks for quick reply! 🙌🏻 Didn't have too much time today to look properly at this, but it looks like getters/setters are not set properly for properties with initial values. Will try to look at it in the following days. |
It's looks like TypeScript's 🎉 What has worked for me is to define a schema class similar to this (see working-solution branch): class State extends Schema {
constructor() {
super();
this.property = "";
this.number = 0;
}
}
defineTypes(State, {
property: "string",
number: "number",
});
interface State extends Schema {
property: string;
number: number;
} |
This seems to only be a problem for TypeScript if you are compiling to ES2022/ESNext. Public instance fields are added to subclass instances using |
Just upgraded my entire stack to compile to ESM and this is the only major issue I've had so far. Would be great to have some movement on this! |
If this is as you say would the solution be to abandon subclassing of schemas entirely; instead turning schemas into typed data containers? const playerSchema = new Schema<PlayerType>({ ...playerData }); It feels similar to what Pinia does for reactive data stores. |
Any solution for using @decorators defining schema? My current solution for this is just change target from esnext to es2018. |
Just found a workaround for this: setting "compilerOptions": {
"useDefineForClassFields": false,
// ...
} This setting may conflict with projects that rely on it being More info: |
works: export class MySchema extends Schema {
constructor(){
super();
this.foo = 3;
}
@type("int32") foo: number;
} doesn't work: export class MySchema extends Schema {
@type("int32") foo: number = 3;
// presumably the getters and setters are clobbered?
// at any rate the setter is never called if you do this
} |
Closing this as it seems a non-issue for the moment. #510 (comment) |
… and Colyseus Let's be friendlier towards Colyseus, shall we? Apparently, `useDefineForClassFields` being `true` by default prevented states from working properly. Because we intend on encouraging Colyseus usage, we should be sure our Robo Compiler defaults play well with it! Ref: colyseus/colyseus#510
Steps to Reproduce
Example CodesSandbox: https://codesandbox.io/s/dazzling-mountain-hwzfxh
ping
message to server.Context
Server receives
ping
messages, but client is not updated with the latest state. Checked with DevTools, server is not sending any message (sends only two at the beginning, I think they are schema types related).Adding @colyseus/monitor, and inspecting room's state also shows empty state.
Your Environment
The text was updated successfully, but these errors were encountered: