Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Conversation

wingleung
Copy link

PR for #27

@wingleung wingleung changed the title Usa hydrate instead of render starting from react 16 Use hydrate() instead of render() starting from react 16 Oct 10, 2017
package.json Outdated
"sinon-sandbox": "^1.0.2"
},
"dependencies": {
"semver": "^5.4.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1200 LOC just so we can support both Reacts at the same time? I'd rather semver breaking and backport fixes. Having two different branches is not worth it IMO.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another alternative is letting the default entry point be "render" and providing a new entry point for "hydrate".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a separate function for hydrate

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another alternative is calling hydrate when it's present, and otherwise just fall back to render - checking the React version is brittle anyways

@wingleung wingleung force-pushed the feature/hydration-instead-of-render branch 3 times, most recently from f827c18 to a22c131 Compare October 11, 2017 18:00
package.json Outdated
"hypernova": "^2.0.0",
"react": "0.14.x || >= 15.x",
"react-dom": "0.14.x || >= 15.x"
"react": "0.14.x || >= 15.x || >= 16.x",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>= 15.x actually already includes 16.x, so these lines don't really need to change (altho they should probably change to ^0.14 || ^15 || ^16 instead of using >=

Copy link
Author

@wingleung wingleung Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb done, however I'm not sure why this was even necessary from the start. Couldn't we just do >0.14? or do we have to ignore 0.15? In that case we should probably use ~0.14 instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to use ~0.14, I suspect we have to ignore 0.15 for some reason?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no 0.15.

@wingleung wingleung force-pushed the feature/hydration-instead-of-render branch 2 times, most recently from e3ce178 to e5bc6aa Compare October 12, 2017 18:08
package.json Outdated
"react": "0.14.x || >= 15.x",
"react-dom": "0.14.x || >= 15.x"
"react": "~0.14 || ^15 || ^16",
"react-dom": "~0.14 || ^15 || ^16"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ for versions below 1.0 only updates the patch, so ^0.14 is correct here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, thanks for bearing with me on this. Really, I'm gaining knowledge here!

@wingleung wingleung force-pushed the feature/hydration-instead-of-render branch from e5bc6aa to 7c68975 Compare October 13, 2017 07:07
Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

We should probably try to add some kind of test; the test would probably just assert that when ReactDOM.hydrate was a function, it called it; else it called render.

@wingleung wingleung force-pushed the feature/hydration-instead-of-render branch from 7c68975 to 5cc94b6 Compare October 13, 2017 20:38
@wingleung
Copy link
Author

@ljharb Added tests

global.window = window;
global.document = window.document;

const hydrateMethod = sinon.spy(ReactDOM, 'hydrate');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this work when hydrate doesn't exist yet?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb yes, this test runs in the hypernova-react package which (in this PR) depends on React ^16 and therefore always has the hydrate method available.
https://github.com/airbnb/hypernova-react/pull/30/files

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hypernova-react doesn't depend on v16, it devDepends on it, and peerDepends on 0.14 or 0.15 or 16 - if we wanted to test this repo on 0.14 or 0.15 (which we should, if we're not already), this test would fail.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will we switch the react version to in our test cases? Shouldn't we use v16 and mock v15/v0.14 behaviour, which I'm doing on line 59

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for this PR :-) when we actually add tests on all the React versions, we wouldn't want to mock things out - mocks make tests more brittle.

@sebjacobs
Copy link

Are there any plans to merge this PR?

Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this last change, and rebase, and this will be good to go.

"mocha": "^4.0.0",
"prop-types": "^15.6.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devDep and peerDep ranges should all be identical; let's make those the same

"react": "^15.6.1",
"react-dom": "^15.6.1",
"react": "^0.14 || ^15 || ^16",
"react-dom": "^0.14 || ^15 || ^16",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb like this? when I test this it always installs v16

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep! that's fine, it will always install the latest, but it will be valid to install older versions.

@ljharb
Copy link
Collaborator

ljharb commented Nov 22, 2017

@wingleung last thing needed is to rebase on latest master; i'm happy to do it for you if needed.

@wingleung wingleung force-pushed the feature/hydration-instead-of-render branch from fc218f9 to c00c0e0 Compare November 22, 2017 16:28
@wingleung
Copy link
Author

@ljharb rebase done

@ljharb ljharb force-pushed the feature/hydration-instead-of-render branch from c00c0e0 to 82b92ba Compare November 22, 2017 16:54
@ljharb ljharb merged commit 82b92ba into airbnb:master Nov 22, 2017
ljharb added a commit that referenced this pull request Nov 30, 2017
 - [New] Use hydrate when possible (#30)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants