cerebral/overmind

overmind.hydrate() does not return anything

agritheory opened this issue ยท 12 comments

This reproduction may be easier to understand than a description of the issue.

Calling overmind.hydrate() on the server (Nuxt) does not return the serialized mutations to state as expected. Christian seems to think it might be related to events not registering or something specific to the Nuxt environment.

Okay, this is insanely weird. In the Nuxt environment, this resolves to false:

Object.getPrototypeOf({}) === Object.prototype

If you run this on Node it resolves to true, and it should. This is also the case for the browser. Like... {} IS the base object of JS. I have no idea what Nuxt is doing to mess this up.

Maybe Babel is doing something crazy?

Even weirder... this ONLY happens in the overmind.js file, not in the middleware or plugin

Okay, when I removed merge from the overmind.js file it suddenly got correct prototypes, but that problem continues to happen in the overmind.plugin.js file

Okay, I am super confused... suddenly it starts logging out the right thing, but as I move logging into the Overmind library (in node_modules) it starts failing again. So logging:

console.log("WTF NUXT????", Object.getPrototypeOf(config.state) === Object.prototype);

From app code works, but when I log the exact same thing inside node_modules and createOvermindSSR function, it logs false for the same thing

overmind.plugin.js
Screenshot 2021-02-28 at 09 28 00

node_modules/overmind/index
Screenshot 2021-02-28 at 09 28 13

First one resolves to true, the other to false ... this is just insane?

I could do a different check for is_plain_obj, but it bugs the hell out of me why this happens, it makes absolutely no sense... and it only happens in Nuxt environment...

I did some more digging and found a couple of environment issues as well. But yeah, I have no idea why suddenly the Object prototype fails inside the Overmind package. It is insanely weird. Anyways, will fix this ๐Ÿ˜„

Okay, I pushed a fix now, will test it when CI has done its job ๐Ÿ˜„

@christianalfoni In the reproduction case above, I updated the Overmind branch to 'next' and it's hanging the browser in both Firefox and Brave.

You have to update both packages ๐Ÿ˜„ here it is running: https://codesandbox.io/s/confident-wu-tiyv0

Awesome, thank you!

Released! ๐ŸŽ‰