-
Notifications
You must be signed in to change notification settings - Fork 44
Use hydrate() instead of render() starting from react 16 #30
Use hydrate() instead of render() starting from react 16 #30
Conversation
package.json
Outdated
"sinon-sandbox": "^1.0.2" | ||
}, | ||
"dependencies": { | ||
"semver": "^5.4.1" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
f827c18
to
a22c131
Compare
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", |
There was a problem hiding this comment.
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 >=
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
e3ce178
to
e5bc6aa
Compare
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
e5bc6aa
to
7c68975
Compare
There was a problem hiding this 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
.
7c68975
to
5cc94b6
Compare
@ljharb Added tests |
global.window = window; | ||
global.document = window.document; | ||
|
||
const hydrateMethod = sinon.spy(ReactDOM, 'hydrate'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Are there any plans to merge this PR? |
There was a problem hiding this 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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@wingleung last thing needed is to rebase on latest master; i'm happy to do it for you if needed. |
fc218f9
to
c00c0e0
Compare
@ljharb rebase done |
c00c0e0
to
82b92ba
Compare
PR for #27