Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

React 16 + Ref Support #106

Merged
merged 6 commits into from
Nov 6, 2018
Merged

React 16 + Ref Support #106

merged 6 commits into from
Nov 6, 2018

Conversation

thomashuston
Copy link
Contributor

I've been spending a bit of time this week seeing if we can get SeatGeek working with Percy for a project I'm working on. I'm pretty close, but was running into a few issues which I've addressed in this PR:

  1. @percy/react was restricting peer dependencies to only React v15, but React v16 has been out for a year. I've updated the peer dependencies allow both v15 and v16, and updated the unit tests here to run against v16.

  2. I discovered that refs don't work properly because we were loading two copies of React on the page when snapshotting (it was included in both the snapshots and render bundles). I've updated the webpack config to extract react and react-dom into a vendor bundle to prevent it from loading multiple times, and added some integration tests here to verify that refs work. The tests failed before my changes, and now render properly with my updates.

"react-dom": "^15.6.1"
"prop-types": "^15.6.2",
"react": "^16.5.2",
"react-dom": "^16.5.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A while back we discussed adding better integration test coverage of multiple React versions. Might be worth a separate PR that adds coverage for both React 15 and 16 and both create-react-app 1 and 2.

@@ -44,6 +45,9 @@
"<rootDir>/integration-tests/",
"<rootDir>/packages/"
],
"setupFiles": [
"raf/polyfill"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

React 16 requires a requestAnimationFrame polyfill for tests to run properly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like Jest 21.3.x included the polyfill by default. Maybe we can bump the version of Jest here (or a separate PR?) jestjs/jest#4568 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, I’ll toss up a separate PR for that next week. I’m off on vacation till then :)

"react": "^15.4.0",
"react-dom": "^15.4.0"
"react": "^15.4.0 || ^16.0.0",
"react-dom": "^15.4.0 || ^16.0.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows users to have either React 15 or React 16 in their projects without getting any peer dependency warnings.

@@ -25,9 +25,15 @@ export default async function run(percyConfig, percyToken) {
const assets = await compile(percyConfig);

const environment = new Environment();
const runtimeEntry = findEntryPath(assets, EntryNames.runtime);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The runtime entry contains a manifest webpack uses to make sure imports work correctly across entries now that we're splitting some dependencies out into the vendor bundle. The vendor bundle contains react and react-dom, so that they're not included in multiple scripts.

@@ -17,6 +17,9 @@ jest.mock('redbox-react', () => ({ error }) =>
);
/* eslint-enable react/display-name, react/prop-types */

// eslint-disable-next-line no-console
console.error = jest.fn();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test purposefully causes an error to get thrown so we can verify it's getting rendered. React 16 has a new mechanism for catching errors and prints a console error here, but it's not really useful in the context of this test.

@thomashuston
Copy link
Contributor Author

@timhaines any ideas why the create-react-app snapshots are rendering blank? I ran react-percy --debug on that integration test project locally and loaded it up, and everything looks fine. Are some scripts not getting uploaded properly or something?

Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

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

Other than the raf polyfill everything looks good. I wonder why the snapshots are blank though 🤔

@@ -44,6 +45,9 @@
"<rootDir>/integration-tests/",
"<rootDir>/packages/"
],
"setupFiles": [
"raf/polyfill"
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like Jest 21.3.x included the polyfill by default. Maybe we can bump the version of Jest here (or a separate PR?) jestjs/jest#4568 (comment)

Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

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

I ran the changes locally and compared snapshots between this & the released version. Everything looks good to me! 👍

@Robdel12 Robdel12 merged commit 208e253 into master Nov 6, 2018
@Robdel12 Robdel12 deleted the th-react-updates branch December 18, 2018 21:15
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.

2 participants