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

dehydrated value of RouteStore contains action value [fluxible-router v1] #522

Open
geta6 opened this issue Mar 13, 2017 · 5 comments · Fixed by #670
Open

dehydrated value of RouteStore contains action value [fluxible-router v1] #522

geta6 opened this issue Mar 13, 2017 · 5 comments · Fixed by #670

Comments

@geta6
Copy link
Contributor

geta6 commented Mar 13, 2017

When dehydrate RouteStore on server side, the value contains action of RouteStore.
I’m in troubled that transpiled code is exported to client side by server side setting.

I want the dehydrated value of RouteStore to be abstracted as before.

RouteStore

RouteStore.withStaticRoutes({
  index: {
    path: '/',
    handler: IndexComponent,
    action: async (context) => {
      await Promise.all([
        context.executeAction(FooAction, {}),
        context.executeAction(BarAction, {}),
      ]);
    },
  }
})

v0.4.x dehydrated value

{
  "RouteStore":{
    "currentUrl":"\u002F",
    "currentNavigate":{
      "transactionId":2953444313308840,
      "url":"\u002F",
      "config":{},
      },
    "currentNavigateError":null,
    "isNavigateComplete":true,
    "routes":null
  }
}

v1.0.0 dehydrated value

{
  "RouteStore":{
    "currentNavigate":{
      "transactionId":6733112344216282,
      "url":"\u002F",
      "config":{}
      "route":{
        "path":"\u002F",
        "handler":function StoreConnector(props, context) {
          React.Component.apply(this, arguments);
          this.state = this.getStateFromStores();
          this._onStoreChange = null;
          this._isMounted = false;
        },
        "action":async (context) => {
          await Promise.all([
            context.executeAction(FooAction, {}),
            context.executeAction(BarAction, {}),
          ]);
        },
        "method":"GET",
        "name":"index",
        "url":"\u002F",
        "params":{},
        "query":{}
      },
      "error":null,
      "isComplete":true
    },
    "routes":null
  }
}

Steps to reproduce the behavior

  1. Transpile javascript with different babel settings on server and client.
    - server: ['env', { targets: { node: 'current' } }]
    - client: ['env', { targets: { browsers: [...] } }]
  2. Set async function in action to create RouteStore.
  3. Embed the serialized dehydrate value in the template and render it.
  4. Open in browser that not compatible with async/await.
    - SyntaxError: Unexpected token '=>'
    - Error: `rehydrate` called with a non-object. Ensure that the parameter passed to rehydrate is a state object produced by a dehydrate call.
@mridgway
Copy link
Collaborator

I think I see what's going on. In previous versions we did not dehydrate the currentRoute which contained the navigation object. Since we inverted these values in 1.0, we may need to strip out the route from currentNavigate.

@mridgway
Copy link
Collaborator

Yeah, we already rehydrate the route part correctly, we just don't remove the route in https://github.com/yahoo/fluxible/blob/master/packages/fluxible-router/lib/RouteStore.js#L141

@pwmckenna
Copy link
Contributor

We just extended the RouteStore, overwrote the dehydrate function and stripped out the route. Has been working fine in production for weeks.

@xbIm
Copy link

xbIm commented Apr 24, 2017

@pwmckenna can you please share a code snippet for this fix?

@pwmckenna
Copy link
Contributor

pwmckenna commented May 1, 2017

@xbIm

class extends RouteStore.withStaticRoutes(routes) {
    dehydrate() {
        const {
            currentNavigate: {
                route,
                ...currentNavigate
            },
            ...dehydrated
        } = super.dehydrate();
        return {
            ...dehydrated,
            currentNavigate
        };
    }
}

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

Successfully merging a pull request may close this issue.

4 participants