Can't use AppState with SSR?


#1

I have the following in one of my components:

  getMeteorData() {
    return {
      formFields: AppState.get('formFields')
    }
  },

I get a server error about AppState not being defined, which makes sense. Is there no way to use this package in an SSR environment, @luisherranz? Or do I just need to do something along the lines of:

  getMeteorData() {
    return {
      formFields: Meteor.isClient ? AppState.get('formFields') : {}
    }
  },

…since bots don’t care about functionality. :slight_smile:


#2

I haven’t explored SSR yet, mostly because the app I’m building doesn’t need SEO yet and we need to use Blaze, but feel free to let me know what is needed or make a pull request.

By the way, we are playing a lot with AppState until we figure out the best way to make it work with Meteor, so we created a new package called ReactiveState which has the old AppState functionality for those of you using it already.

If you do a pull request with SSR support, please do it to that package and not to AppState.


#3

Thanks for the heads up! I honestly don’t know the best way to build an SSR app yet, there’s a lot I don’t understand. I keep putting it off for the time being.

I’ll definitely check out ReactiveState, as another project of mine is already too ingrained with the Flux pattern that I don’t want to have to refactor to use Redux style.

Thanks!


#4

There still things not working smoothly between Redux and Meteor due to the asyn and caothic nature of Tracker. It’s not safe to start using AppState as it is now but I think we are near.


#5

Ah! Then for a production app I should probably be using ReactiveState then.


#6

Yes, you can use ReactiveState and if you find any bug post an issue on Github.