<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Client throws when setState is called in server room]]></title><description><![CDATA[<p>I have this basic client code:</p>
<pre><code>        if(this.state.game_started) {
            console.log(&quot;Game already started&quot;)
            return
        }
        this.setState({
            game_started:true
        })
        this.client=new Client(&quot;ws://localhost:2657&quot;)

        this.room=this.client.join(&quot;game-room&quot;)
        this.room.onJoin.add(()=&gt;{
            console.log(`Joined room with client id ${this.client.id}`)
        })
        this.room.onStateChange.add(()=&gt;{
            console.log(&quot;State change:&quot;)
            console.log(this.room.state)
            this.forceUpdate()
        })
</code></pre>
<p>This is using React.</p>
<p>And this basic server room:</p>
<pre><code>const colyseus=require(&quot;colyseus&quot;)

class GameRoom extends colyseus.Room {

    constructor(){
        super(...arguments)
        this.maxClients=2
    }

    onInit(options){
        // this.setState({
    //         message_history: []
    //     })
        this.setState({})
        this.state={
            messages:[]
        }
    }

    requestJoin(options, isNewRoom) {
        return true
    }

    onJoin(client, options, auth) {
        console.log(`Client with id ${client.id} joined.  Options: ${JSON.stringify(options)}`)
        this.state.messages.push({
            sender:&quot;Server&quot;,
            content:`Client with id ${client.id} joined`
        })
    }

    onMessage(client, data) {
        if(data.type===&quot;message&quot;){
            this.state.message_history.push(data.message)
        }
    }

    onLeave(client, consented) {
        console.log(`Client with id ${client.id} left. Consented: ${consented}`)
    }

    onDispose() {
    }

}

module.exports = GameRoom
</code></pre>
<p>When I comment out the <code>setState</code> in <code>onInit</code>, the client joins perfectly fine.  When I leave it uncommented, the client throws this error:</p>
<pre><code>index.js:1446 colyseus.js: server error: SchemaSerializer error. See: https://docs.colyseus.io/migrating/0.10/#new-default-serializer
</code></pre>
<p>And the server prints nothing.</p>
<p>This is using latest version of server and client packages, so why is this happening?</p>
]]></description><link>http://discuss.colyseus.io/topic/231/client-throws-when-setstate-is-called-in-server-room</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 11:39:05 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/231.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 03 Apr 2019 03:23:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Client throws when setState is called in server room on Invalid Date]]></title><description><![CDATA[<p>I have this basic client code:</p>
<pre><code>        if(this.state.game_started) {
            console.log(&quot;Game already started&quot;)
            return
        }
        this.setState({
            game_started:true
        })
        this.client=new Client(&quot;ws://localhost:2657&quot;)

        this.room=this.client.join(&quot;game-room&quot;)
        this.room.onJoin.add(()=&gt;{
            console.log(`Joined room with client id ${this.client.id}`)
        })
        this.room.onStateChange.add(()=&gt;{
            console.log(&quot;State change:&quot;)
            console.log(this.room.state)
            this.forceUpdate()
        })
</code></pre>
<p>This is using React.</p>
<p>And this basic server room:</p>
<pre><code>const colyseus=require(&quot;colyseus&quot;)

class GameRoom extends colyseus.Room {

    constructor(){
        super(...arguments)
        this.maxClients=2
    }

    onInit(options){
        // this.setState({
    //         message_history: []
    //     })
        this.setState({})
        this.state={
            messages:[]
        }
    }

    requestJoin(options, isNewRoom) {
        return true
    }

    onJoin(client, options, auth) {
        console.log(`Client with id ${client.id} joined.  Options: ${JSON.stringify(options)}`)
        this.state.messages.push({
            sender:&quot;Server&quot;,
            content:`Client with id ${client.id} joined`
        })
    }

    onMessage(client, data) {
        if(data.type===&quot;message&quot;){
            this.state.message_history.push(data.message)
        }
    }

    onLeave(client, consented) {
        console.log(`Client with id ${client.id} left. Consented: ${consented}`)
    }

    onDispose() {
    }

}

module.exports = GameRoom
</code></pre>
<p>When I comment out the <code>setState</code> in <code>onInit</code>, the client joins perfectly fine.  When I leave it uncommented, the client throws this error:</p>
<pre><code>index.js:1446 colyseus.js: server error: SchemaSerializer error. See: https://docs.colyseus.io/migrating/0.10/#new-default-serializer
</code></pre>
<p>And the server prints nothing.</p>
<p>This is using latest version of server and client packages, so why is this happening?</p>
]]></description><link>http://discuss.colyseus.io/post/784</link><guid isPermaLink="true">http://discuss.colyseus.io/post/784</guid><dc:creator><![CDATA[mackycheese]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Client throws when setState is called in server room on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/398">@mackycheese</a> The error points you to see this URL: <a href="https://docs.colyseus.io/migrating/0.10/#new-default-serializer" rel="nofollow">https://docs.colyseus.io/migrating/0.10/#new-default-serializer</a></p>
<p>Basically, the new default is to use a class extending the <code>Schema</code> for your state as of version <code>0.10</code>. You can continue using the previous serializer if you'd like to, as stated in the migration guide.</p>
<p>Using React, you can do this in the client-side:</p>
<pre><code>// client-side
this.room.onStateChange.add((newState) =&gt; {
    this.setState(newState);
})
</code></pre>
]]></description><link>http://discuss.colyseus.io/post/785</link><guid isPermaLink="true">http://discuss.colyseus.io/post/785</guid><dc:creator><![CDATA[endel]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Client throws when setState is called in server room on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/1">@endel</a></p>
<p>I see.  Thanks! I switched to the old serializer and it works fine now.  Out of curiosity, why would you switch serializers?</p>
]]></description><link>http://discuss.colyseus.io/post/789</link><guid isPermaLink="true">http://discuss.colyseus.io/post/789</guid><dc:creator><![CDATA[mackycheese]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>