sematable
sematable copied to clipboard
Error when using sematable with server-side rendering
I am including the example AppsTable in a component like so:
return ( ... <AppsTable data={apps} /> ... )
And I can't for the life of me figure out why this is wrong. The server-rendered version is spit out and doesn't contain the table because it renders before AppsTable is initialized (I think). The client-side eventually does render the table and it works, but its not-equal to the server-rendered version and so react/redux throws and error complaining about the difference.
I guess I am not including the table correctly. Could you please point out how it should be done?
Hi,
Assuming that there's nothing wrong in AppsTable, yes, that is how you would use it. Unfortunately, we haven't used or tested sematable with server-side rendering yet, so it's possible that there are some issues.
Maybe you can find some tips here: http://redux.js.org/docs/recipes/ServerRendering.html in case it's not an issue in sematable.
I will keep this issue opened, and try to test sematable with server-side rendering. Thanks for reporting this!
Forgot to ask, but can you please post the exact error you get?
Aha, I see.
The exact errors are (it throws 2):
------snip------
Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server: (client) -reactid="123"><div class="row" data-rea (server) -reactid="123">
app.js:1398 Uncaught Error: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render
method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).
at invariant (app.js:1398)
at Object.addComponentAsRefTo (app.js:14418)
at attachRef (app.js:14280)
at Object.ReactRef.attachRefs (app.js:14299)
at ReactDOMComponent.attachRefs (app.js:14108)
at CallbackQueue.notifyAll (app.js:14012)
at ReactReconcileTransaction.close (app.js:24730)
at ReactReconcileTransaction.closeAll (app.js:15191)
at ReactReconcileTransaction.perform (app.js:15138)
at batchedMountComponentIntoNode (app.js:26815)
------snip------
For the first error, it seems to be the case that when the server tries to include the sematable-wrapped AppsTable component, it is not initialized (I did some debugging and found this to be the case) and so it doesn't render anything. For some reason I couldn't figure out, it doesn't get initialized either, so the result of the server side render() of the parent class becomes just the contents of the parent class, nothing from AppsTable.
For the second error, I believe it is related to how we wrap the AppsTable class with sematable(). Does that make it so the actual react markup gets rendered independently outside of the parent class render()?