Skip to content
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

Merged
merged 10 commits into from Jan 29, 2020
Merged

Hydrationfix #957

merged 10 commits into from Jan 29, 2020

Conversation

prateekbh
Copy link
Member

What kind of change does this PR introduce?

Feature

Did you add tests for your changes?
Yes

Summary

  • Makes AsyncComponent backward compatible
  • Adds a test for progressive hydration(preactX and Preact8)

Does this PR introduce a breaking change?
No

const { existsSync } = require('fs');

function isInstalledVersionPreactXOrAbove(cwd) {
const pathToPreact = resolve(cwd, 'node_modules', 'preact');
Copy link
Member

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?

Suggested change
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;
}

Copy link
Member Author

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('.'))) >=
Copy link
Member

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:

Suggested change
parseInt(preactVersionString.substr(0, preactVersionString.indexOf('.'))) >=
parseInt(preactVersionString, 10) >=

Copy link
Member Author

Choose a reason for hiding this comment

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

TIL

Copy link
Member Author

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);
Copy link
Member

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)

Suggested change
old(child);
old.call(this, child);

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@prateekbh prateekbh merged commit b3e9b59 into master Jan 29, 2020
@prateekbh prateekbh deleted the hydrationfix branch January 29, 2020 03:03
@rschristian rschristian mentioned this pull request Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants