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

Uncaught Error: "refId" not found: 31 #128

Open
naive17 opened this issue Apr 13, 2022 · 13 comments
Open

Uncaught Error: "refId" not found: 31 #128

naive17 opened this issue Apr 13, 2022 · 13 comments

Comments

@naive17
Copy link

naive17 commented Apr 13, 2022

image

Hi i'm using colyseus since a bit but now i'm getting this weird error.
As i remove anything from a state that uses ArrayMap on Leave, on the next join all the connected players will receive this error.

@endel
Copy link
Member

endel commented Apr 13, 2022

Hi @naive17, could you please provide a minimal reproduction scenario for this issue you're experiencing?
It could be as a test case, or by sharing a repository where the error can reproduced in a predictable way

@naive17
Copy link
Author

naive17 commented Apr 13, 2022

Sadly i can't share my repo right now since it's a work project and the company isn't mine.
But in the past i had the same exact problem thinkering with your ecs project.
whenever i removed a entity it showed the same problem with ref id (i looked at the code and it was also an ArrayMAp).
Reproducing the repo is a bit hard since it's a really big project.

@amir-arad
Copy link
Contributor

amir-arad commented Aug 14, 2022

@naive17 I'm having similar problems after switching the frontend bundler to use esbuild while the backend still uses typescript.

could you tell us about your build stack?

(my very wild guess is that the schema classes are loaded in a different order)

@naive17
Copy link
Author

naive17 commented Aug 14, 2022

@naive17 I'm having similar problems after switching the frontend bundler to use esbuild while the backend still uses typescript.

could you tell us about your build stack?

Hi!
Sure, i was using vue-cli webpack , then i switched to vite.

@amir-arad
Copy link
Contributor

yeah, vite uses esbuild.
I switched to esbuild-loader myself and stayed in webpack, so it sounds like the same problem more or less.
I'm going to try to pre-bundle the model (all the schema classes) using esbuild and let the server and client both use that same file, will report findings.

@naive17
Copy link
Author

naive17 commented Aug 14, 2022

But i'm not having that problem so frequently now

@amir-arad
Copy link
Contributor

For future reference, pre-bundling the common code worked for me: It prevented the browser bundler from re-arranging the schema files, thus kept the loading order in sync between server and client.
I used tsup because I also needed the d.ts files generated.

@endel I would add a warning to the limitations and best practices documentation : The order of the classes must be the same, meaning that any difference in build tools between client and server that may affect the loading order of the schema files may cause Uncaught Error: "refId" not found errors

@amir-arad
Copy link
Contributor

@naive17 I suspect there is some kind of concurrency race condition in your build job? so that sometimes the same order is kept between client and server, and sometimes not?

@endel
Copy link
Member

endel commented Aug 15, 2022

Interesting, thanks for inspecting and finding this out @amir-arad!

@endel endel pinned this issue Jun 21, 2023
@RaiaN
Copy link

RaiaN commented Apr 30, 2024

What is the resolution? Hitting this issue when using very very basic state...

export class MyState extends Schema {
    @type("number") currentTurn: number;
    @type("string") winner: string;
    
    @type({ map: Player }) players = new MapSchema<Player>();
    @type([ Cell ]) cells = new ArraySchema<Cell>();
}

MyState has some getters as well but I don't believe they cause this error

@RaiaN
Copy link

RaiaN commented Apr 30, 2024

What does The order of the fields must be the same. mean in Javascript context?

@endel
Copy link
Member

endel commented Apr 30, 2024

Hi @RaiaN, can you please provide a small reproduction scenario? This issue hasn't been easily reproducible for me.

The "The order of the fields must be the same" generally applies to compiled targets, where schema-codegen must be used to keep the client schemas up-to-date with the server. In JavaScript the structures are generally reflected during room handshake.

@RaiaN
Copy link

RaiaN commented Apr 30, 2024

@endel I am not sure how to repro it. I shuffled the fields again and removed some of the logic from Schema class and the error is gone.. Weird.
I also used MyState class on the client side (even though docs state it is optional?) when joining the room so it looks like this
await client.joinOrCreate<MyState>

My feeling is that actively changing order of the fields while restarting server and client leads to the issue like that. Another thing is recursive structures / schemas. Not sure how well those are supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants