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

Server-side Rendering throws error when using setState within onInput #998

Open
nthibert opened this issue Feb 23, 2018 · 1 comment
Open

Comments

@nthibert
Copy link

Bug Report

Marko Version: 4.5.6

Details

Currently our project is using server-side rendering to build the initial marko components. While developing, our team came across an issue when using setState within the onInput method. On the server-side we get an error TypeError: this.setState is not a function, though browser works fine. My manager and I started talking and looking into the difference between the Component.js and ServerComponent.js. Seems any state change method is not implemented for the ServerComponent.js. A simple code example:

component.js

export default class CounterComp {

    onCreate(input) {
        this.state = {
            counter: input.counter | 0
        };
    }

    onInput(input) {
       this.setState("counter", input.count +1)
    }
}

On server-side render this causes the error.

Expected Behavior

this.setState should not throw error when doing server rendering

Actual Behavior

this.setState throws error

Possible Fix

Implement state changing methods on ServerComponent.js (setSate, replaceState)

Additional Info

Your Environment

  • Environment name and version (e.g. Chrome 39, node.js 5.4):
    **Chrome 64, nodejs 8.6.0
  • Operating System and version (desktop or mobile):
    **Mac OS 10.13.3 Desktop

Stack Trace

TypeError: this.setState is not a function at Modal.onInput (webpack-internal:///54:37:22) at Modal.ServerComponent (webpack-internal:///47:20:37) at ServerComponent (webpack-internal:///46:11:5) at Object.createComponent [as ___createComponent] (webpack-internal:///46:24:21) at renderer (webpack-internal:///44:106:34) at wrappedRenderer (webpack-internal:///52:106:13) at render (webpack-internal:///51:21:3) at renderer (webpack-internal:///44:186:9) at safeRender (webpack-internal:///38:6:9) at Template.render (webpack-internal:///38:136:20)

@ybitso
Copy link

ybitso commented Mar 30, 2019

+1
Marko 4.16.5

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