sematable icon indicating copy to clipboard operation
sematable copied to clipboard

Error when using sematable with server-side rendering

Open malte79 opened this issue 7 years ago • 3 comments

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?

malte79 avatar Feb 28 '17 23:02 malte79

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!

amir-hadzic avatar Mar 01 '17 11:03 amir-hadzic

Forgot to ask, but can you please post the exact error you get?

amir-hadzic avatar Mar 01 '17 11:03 amir-hadzic

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">

< printWarning @ app.js:1830 warning @ app.js:1854 _mountImageIntoNode @ app.js:27196 mountComponentIntoNode @ app.js:26801 perform @ app.js:15125 batchedMountComponentIntoNode @ app.js:26815 perform @ app.js:15125 batchedUpdates @ app.js:24312 batchedUpdates @ app.js:13778 _renderNewRootComponent @ app.js:27009 _renderSubtreeIntoContainer @ app.js:27090 render @ app.js:27111 render @ app.js:117293 (anonymous) @ app.js:10458 webpack_require @ app.js:556 fn @ app.js:87 (anonymous) @ app.js:587 webpack_require @ app.js:556 (anonymous) @ app.js:579 (anonymous) @ app.js:582

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()?

malte79 avatar Mar 01 '17 16:03 malte79