-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hydrationfix #957
Hydrationfix #957
Conversation
const { existsSync } = require('fs'); | ||
|
||
function isInstalledVersionPreactXOrAbove(cwd) { | ||
const pathToPreact = resolve(cwd, 'node_modules', 'preact'); |
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 wonder if it'd be worth using require.resolve here?
const pathToPreact = resolve(cwd, 'node_modules', 'preact'); | |
let pathToPreact; | |
try { | |
pathToPreact = path.dirname(require.resolve('preact/package.json')); | |
} | |
catch (e) {} |
With this change the whole function could be this:
const resolveFrom = require('resolve-from');
function isInstalledVersionPreactXOrAbove(cwd) {
try {
return parseInt(require(resolveFrom(cwd, 'preact/package.json')), 10) >= 10;
}
catch (e) {}
return false;
}
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.
done
const pathToPackage = resolve(pathToPreact, 'package.json'); | ||
const { version: preactVersionString } = require(pathToPackage); | ||
return ( | ||
parseInt(preactVersionString.substr(0, preactVersionString.indexOf('.'))) >= |
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.
parseInt()
parses the first integer so it'll already return only the major:
parseInt(preactVersionString.substr(0, preactVersionString.indexOf('.'))) >= | |
parseInt(preactVersionString, 10) >= |
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.
TIL
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.
done
const old = root.removeChild; | ||
root.removeChild = child => { | ||
window.ROOT_MUTATION_COUNT++; | ||
old(child); |
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.
this would throw (thankfully it's not being called! haha)
old(child); | |
old.call(this, child); |
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.
done
What kind of change does this PR introduce?
Feature
Did you add tests for your changes?
Yes
Summary
Does this PR introduce a breaking change?
No