Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

make component isomorphic friendly #15

Closed
wants to merge 1 commit into from

Conversation

gregory90
Copy link

Moved touch detection to componentDidMount so we won't run that code on the server.

@balloob
Copy link
Owner

balloob commented Sep 11, 2015

Using typeof window === 'object' should already make sure that that code is not executed on the server.

@gregory90
Copy link
Author

Problem lies elsewhere. If you do npm install react-sidebar you get commit 551068b4821665a9592aafac3b3cfb6e0743b81d with old dist-modules(updated in commit acd8d00d120f911808e46207783522e06850760b).

Sorry for the confusion.

@balloob
Copy link
Owner

balloob commented Sep 11, 2015

Updated dist-modules and pushed to master, 0643894, will push a new npm release too

@balloob balloob closed this Sep 11, 2015
@gregory90
Copy link
Author

Thanks!

@gregory90 gregory90 deleted the isomorphic-friendly branch September 11, 2015 23:23
@elliottsj
Copy link
Contributor

Setting dragSupported in the constructor leads to an issue where the server-rendered markup differs from the client render. On the server, dragSupported starts as false, so useTouch === false and no dragHandle is rendered. On the client, dragSupported starts as true, so useTouch === true and React tries to render the dragHandle, but this error is raised due to the different markup:

Unhandled promise rejection Error: You're trying to render a component to the document using server rendering but the checksum was invalid. This usually means you rendered a different component type or props on the client from the one on the server, or your render() methods are impure. React cannot handle this case due to cross-browser quirks by rendering at the document root. You should look for environment dependent code in your components and ensure the props are the same client and server side:
 (client) a-reactid="29"><div style="z-index:1;pos
 (server) a-reactid="29"><div data-reactid="30"><s
    at invariant (webpack:///./~/fbjs/lib/invariant.js?:38:15)
    at Object.ReactMount._mountImageIntoNode (webpack:///./~/react/lib/ReactMount.js?:451:91)
    at Object.wrapper [as _mountImageIntoNode] (webpack:///./~/react/lib/ReactPerf.js?:66:21)
    at mountComponentIntoNode (webpack:///./~/react/lib/ReactMount.js?:110:14)
    at ReactReconcileTransaction.Mixin.perform (webpack:///./~/react/lib/Transaction.js?:136:20)
    at batchedMountComponentIntoNode (webpack:///./~/react/lib/ReactMount.js?:124:15)
    at ReactDefaultBatchingStrategyTransaction.Mixin.perform (webpack:///./~/react/lib/Transaction.js?:136:20)
    at Object.ReactDefaultBatchingStrategy.batchedUpdates (webpack:///./~/react/lib/ReactDefaultBatchingStrategy.js?:63:19)
    at Object.batchedUpdates (webpack:///./~/react/lib/ReactUpdates.js?:97:20)
    at Object.ReactMount._renderNewRootComponent (webpack:///./~/react/lib/ReactMount.js?:277:18

The client should have dragSupported start as false to properly reconcile with the server markup, as in this PR.

@elliottsj
Copy link
Contributor

I've re-created this PR as #44, retaining @gregory90's original commit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants