-
Notifications
You must be signed in to change notification settings - Fork 27
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
[v15] refactor(app-shell): use react-apollo v3 #801
Conversation
queryName: 'applicationsMenuQuery', | ||
skipRemoteQuery: ownProps => !ownProps.environment.servedByProxy, | ||
options: ownProps => ({ | ||
export const NavBar = props => { |
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.
We're using several hooks here and the code is much more readable now!
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 agree and appriciate this. However, I would also argue that we should split updating libs and refactoring code. So we only change as little as possible in dep updates and keep such changes for other PRs. I am just arguing for this in the future as we had quite a few regressions in the last weeks.
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.
Yeah sure, I agree 👌
Just for the record, those refactorings were part of the experimental branch of using the Apollo hooks 2 months ago or something.
}; | ||
|
||
// Use `withRouter` to "connect" again, to access the `location` object | ||
export default withRouter(NavBar); |
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.
Just one HOC left 🙌
// We can assume here that the navbar already fetched the data, since this | ||
// component gets rendered only when the user opens the menu | ||
fetchPolicy: 'cache-only', | ||
onError: reportErrorToSentry, |
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 is also interesting and I think we should do that more often. When we don't specifically handle the apollo error
, we can just bind the error handler with our sentry reporter.
}); | ||
}); | ||
}); | ||
|
||
describe('<UserSettingsMenuBody>', () => { | ||
beforeEach(() => { | ||
useApplicationsMenu.mockReturnValue({ |
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.
Easy peasy 🤓
options: {}, | ||
}; | ||
|
||
const useApplicationsMenu = (config = {}) => { |
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 also got nicer and easier to follow (I hope)
So apparently we need to update to react >=16.9 and testing-library/react@>=8 in order to fix this problem |
1edbbf3
to
979dd7b
Compare
Should we coordinate on making the required test fixes to MC-FE to upgrade to latest RTL there then? |
Yeah we need to discuss how we want to proceed here. This PR is not meant to be merged just yet, I just want to experiment and see what we need to do in order to support newer versions. |
Either way it would be a good idea to update MC FE to latest testing library version... 😄 |
Definitely! I added a comment in the v14 issue, to keep track of it: #748 (comment) Btw, what was the problem with updating to latest RTL? |
the breaking changes are listed here https://github.com/testing-library/dom-testing-library/releases/tag/v4.0.0 getBy:* All getBy and findBy query variants now will throw an error if more than one element is returned. If this is expected, then use getAllBy (or findAllBy) instead. |
b620008
to
d275102
Compare
058cc31
to
1be22d9
Compare
9221df0
to
efd2a8b
Compare
Now that the new apollo hooks are out, I'm going to pick this up again |
Maybe we should update to rc version of React 16.9? I had a lot of trouble testing async hooks with the current version... |
} | ||
const FetchUser = props => { | ||
const { loading, data, error } = useQuery(LoggedInUserQuery, { | ||
onError: reportErrorToSentry, |
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.
Same here
@@ -24,7 +24,7 @@ export class InjectReducers extends React.PureComponent { | |||
this.setState({ areReducersInjected: true }); | |||
} | |||
|
|||
UNSAFE_componentWillUnmount() { | |||
componentWillUnmount() { |
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.
componentWillUnmount
is not a deprecated lifecycle method. I guess this was confused with componentWillMount
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.
Prolly a find and replace gone rogue.
this.setState({ historyEntries }) | ||
} | ||
onHistoryEntriesChange={historyEntries => { | ||
if (!this.isUnmounting) { |
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.
Without this check, React throws a
Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in
@@ -82,17 +82,6 @@ export function createL10NInjector<LoadedData extends {}>({ | |||
propLoadingKey, | |||
loadLocale, | |||
}: InjectorOptions<LoadedData>) { | |||
if (process.env.NODE_ENV === 'test') { | |||
if (React.version.startsWith('16.8')) { |
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.
We can get rid of this now 🎉
Alright, this is now ready for review and merge. I fixed all the issues within the v15 branch, so let's merge this before doing any more work on the v15 branch. /cc @tdeekens |
} | ||
const FetchProject = props => { | ||
const { loading, data, error } = useQuery(ProjectQuery, { | ||
onError: reportErrorToSentry, |
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.
We didn't do this before though, right? Does Apollo maybe have a more generic way to do this e.g. in a link? So we have a SentryErrorReportingLink which enables us having all errors also from the app to be reported? Can be a follow up I just scratched my head cause we added this here now.
@@ -24,7 +24,7 @@ export class InjectReducers extends React.PureComponent { | |||
this.setState({ areReducersInjected: true }); | |||
} | |||
|
|||
UNSAFE_componentWillUnmount() { | |||
componentWillUnmount() { |
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.
Prolly a find and replace gone rogue.
queryName: 'applicationsMenuQuery', | ||
skipRemoteQuery: ownProps => !ownProps.environment.servedByProxy, | ||
options: ownProps => ({ | ||
export const NavBar = props => { |
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 agree and appriciate this. However, I would also argue that we should split updating libs and refactoring code. So we only change as little as possible in dep updates and keep such changes for other PRs. I am just arguing for this in the future as we had quite a few regressions in the last weeks.
packages/application-shell/src/hooks/use-applications-menu/use-applications-menu.js
Outdated
Show resolved
Hide resolved
packages/application-shell/src/hooks/use-applications-menu/use-applications-menu.js
Outdated
Show resolved
Hide resolved
// We set up the apollo query as lazy, in order to execute it conditionally | ||
// since hooks cannot be defined conditionally. | ||
const environment = useApplicationContext(context => context.environment); | ||
const [loadMenuData, { called, data }] = useLazyQuery(FetchApplicationsMenu, { |
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.
Nice! Stumbled over this for a minute. Should we maybe alias called
to hasApplicationsMenuQueryBeenCalled
. I don't know, would just've helped me. I think it's something which will freak me out with Apollo and hooks is that we'll have these super gernic data
and called
variable names around.
@tdeekens anything else left from your side? |
Not really. It's too general to apply here.
|
}, | ||
}, | ||
onMenuItemClick: jest.fn(), | ||
// areProjectExtensionsEnabled: true, |
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.
why are these lines commented?
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.
We don't use HOCs anymore, so they are not necessary.
TL;DR: we need to rewrite the tests to RTL 😅
Did you require another review by @amine-benselim or not @emmenko? |
Hmm no I didn't |
no he didnt. I was reviewing it while he merged it. so I just continued doing so to know what changed anyway. |
* chore: update to react@16.9 (#966) * chore: update to react@16.9 * fix: update lifecyle methods * chore: temporary resolution for react * chore(deps): update dependency @testing-library/react to v9.1.1 (#956) * chore(deps): update dependency @testing-library/react to v8.0.9 * chore: update testing library to 9.1.1 * fix: remove cleanup-after-each hook (automatical now) * refactor: to remove path for act * refactor(app-shell): use react-apollo v3, use more hooks * refactor(app-shell): do not render hooks conditionally * chore: update react deps consistently * refactor(authenticated): do not render hook conditionally * chore: patch jest setup to avoid logging certain warnings on CI * fix: missing prop ref * fix(navbar): missing prop * refactor(app-connectors): to useQuery for fetching image regex setting * refactor(app-shell): connectors to useQuery * test(app-shell): fix setup * chore: regenerate lockfile * chore: update react-apollo to 3.0.1 * refactor(connectors): image regex tests to RTL * fix: query mocks for project suspended * fix: pin react-test-renderer to 16.9 * fix(quick-access): update state unless component is unmounting * refactor: componentWillUnmount is not a deprecated lifecycle method * test: cleanup * refactor: renaming based on feedback
* chore: update to react@16.9 (#966) * chore: update to react@16.9 * fix: update lifecyle methods * chore: temporary resolution for react * chore(deps): update dependency @testing-library/react to v9.1.1 (#956) * chore(deps): update dependency @testing-library/react to v8.0.9 * chore: update testing library to 9.1.1 * fix: remove cleanup-after-each hook (automatical now) * refactor: to remove path for act * refactor(app-shell): use react-apollo v3, use more hooks * refactor(app-shell): do not render hooks conditionally * chore: update react deps consistently * refactor(authenticated): do not render hook conditionally * chore: patch jest setup to avoid logging certain warnings on CI * fix: missing prop ref * fix(navbar): missing prop * refactor(app-connectors): to useQuery for fetching image regex setting * refactor(app-shell): connectors to useQuery * test(app-shell): fix setup * chore: regenerate lockfile * chore: update react-apollo to 3.0.1 * refactor(connectors): image regex tests to RTL * fix: query mocks for project suspended * fix: pin react-test-renderer to 16.9 * fix(quick-access): update state unless component is unmounting * refactor: componentWillUnmount is not a deprecated lifecycle method * test: cleanup * refactor: renaming based on feedback
* chore: update to react@16.9 (#966) * chore: update to react@16.9 * fix: update lifecyle methods * chore: temporary resolution for react * chore(deps): update dependency @testing-library/react to v9.1.1 (#956) * chore(deps): update dependency @testing-library/react to v8.0.9 * chore: update testing library to 9.1.1 * fix: remove cleanup-after-each hook (automatical now) * refactor: to remove path for act * refactor(app-shell): use react-apollo v3, use more hooks * refactor(app-shell): do not render hooks conditionally * chore: update react deps consistently * refactor(authenticated): do not render hook conditionally * chore: patch jest setup to avoid logging certain warnings on CI * fix: missing prop ref * fix(navbar): missing prop * refactor(app-connectors): to useQuery for fetching image regex setting * refactor(app-shell): connectors to useQuery * test(app-shell): fix setup * chore: regenerate lockfile * chore: update react-apollo to 3.0.1 * refactor(connectors): image regex tests to RTL * fix: query mocks for project suspended * fix: pin react-test-renderer to 16.9 * fix(quick-access): update state unless component is unmounting * refactor: componentWillUnmount is not a deprecated lifecycle method * test: cleanup * refactor: renaming based on feedback
* chore: update to react@16.9 (#966) * chore: update to react@16.9 * fix: update lifecyle methods * chore: temporary resolution for react * chore(deps): update dependency @testing-library/react to v9.1.1 (#956) * chore(deps): update dependency @testing-library/react to v8.0.9 * chore: update testing library to 9.1.1 * fix: remove cleanup-after-each hook (automatical now) * refactor: to remove path for act * refactor(app-shell): use react-apollo v3, use more hooks * refactor(app-shell): do not render hooks conditionally * chore: update react deps consistently * refactor(authenticated): do not render hook conditionally * chore: patch jest setup to avoid logging certain warnings on CI * fix: missing prop ref * fix(navbar): missing prop * refactor(app-connectors): to useQuery for fetching image regex setting * refactor(app-shell): connectors to useQuery * test(app-shell): fix setup * chore: regenerate lockfile * chore: update react-apollo to 3.0.1 * refactor(connectors): image regex tests to RTL * fix: query mocks for project suspended * fix: pin react-test-renderer to 16.9 * fix(quick-access): update state unless component is unmounting * refactor: componentWillUnmount is not a deprecated lifecycle method * test: cleanup * refactor: renaming based on feedback
* chore: update to react@16.9 (#966) * chore: update to react@16.9 * fix: update lifecyle methods * chore: temporary resolution for react * chore(deps): update dependency @testing-library/react to v9.1.1 (#956) * chore(deps): update dependency @testing-library/react to v8.0.9 * chore: update testing library to 9.1.1 * fix: remove cleanup-after-each hook (automatical now) * refactor: to remove path for act * refactor(app-shell): use react-apollo v3, use more hooks * refactor(app-shell): do not render hooks conditionally * chore: update react deps consistently * refactor(authenticated): do not render hook conditionally * chore: patch jest setup to avoid logging certain warnings on CI * fix: missing prop ref * fix(navbar): missing prop * refactor(app-connectors): to useQuery for fetching image regex setting * refactor(app-shell): connectors to useQuery * test(app-shell): fix setup * chore: regenerate lockfile * chore: update react-apollo to 3.0.1 * refactor(connectors): image regex tests to RTL * fix: query mocks for project suspended * fix: pin react-test-renderer to 16.9 * fix(quick-access): update state unless component is unmounting * refactor: componentWillUnmount is not a deprecated lifecycle method * test: cleanup * refactor: renaming based on feedback
* chore: update to react@16.9 (#966) * chore: update to react@16.9 * fix: update lifecyle methods * chore: temporary resolution for react * chore(deps): update dependency @testing-library/react to v9.1.1 (#956) * chore(deps): update dependency @testing-library/react to v8.0.9 * chore: update testing library to 9.1.1 * fix: remove cleanup-after-each hook (automatical now) * refactor: to remove path for act * refactor(app-shell): use react-apollo v3, use more hooks * refactor(app-shell): do not render hooks conditionally * chore: update react deps consistently * refactor(authenticated): do not render hook conditionally * chore: patch jest setup to avoid logging certain warnings on CI * fix: missing prop ref * fix(navbar): missing prop * refactor(app-connectors): to useQuery for fetching image regex setting * refactor(app-shell): connectors to useQuery * test(app-shell): fix setup * chore: regenerate lockfile * chore: update react-apollo to 3.0.1 * refactor(connectors): image regex tests to RTL * fix: query mocks for project suspended * fix: pin react-test-renderer to 16.9 * fix(quick-access): update state unless component is unmounting * refactor: componentWillUnmount is not a deprecated lifecycle method * test: cleanup * refactor: renaming based on feedback
* chore: update to react@16.9 (#966) * chore: update to react@16.9 * fix: update lifecyle methods * chore: temporary resolution for react * chore(deps): update dependency @testing-library/react to v9.1.1 (#956) * chore(deps): update dependency @testing-library/react to v8.0.9 * chore: update testing library to 9.1.1 * fix: remove cleanup-after-each hook (automatical now) * refactor: to remove path for act * refactor(app-shell): use react-apollo v3, use more hooks * refactor(app-shell): do not render hooks conditionally * chore: update react deps consistently * refactor(authenticated): do not render hook conditionally * chore: patch jest setup to avoid logging certain warnings on CI * fix: missing prop ref * fix(navbar): missing prop * refactor(app-connectors): to useQuery for fetching image regex setting * refactor(app-shell): connectors to useQuery * test(app-shell): fix setup * chore: regenerate lockfile * chore: update react-apollo to 3.0.1 * refactor(connectors): image regex tests to RTL * fix: query mocks for project suspended * fix: pin react-test-renderer to 16.9 * fix(quick-access): update state unless component is unmounting * refactor: componentWillUnmount is not a deprecated lifecycle method * test: cleanup * refactor: renaming based on feedback
* chore: update to react@16.9 (#966) * chore: update to react@16.9 * fix: update lifecyle methods * chore: temporary resolution for react * chore(deps): update dependency @testing-library/react to v9.1.1 (#956) * chore(deps): update dependency @testing-library/react to v8.0.9 * chore: update testing library to 9.1.1 * fix: remove cleanup-after-each hook (automatical now) * refactor: to remove path for act * refactor(app-shell): use react-apollo v3, use more hooks * refactor(app-shell): do not render hooks conditionally * chore: update react deps consistently * refactor(authenticated): do not render hook conditionally * chore: patch jest setup to avoid logging certain warnings on CI * fix: missing prop ref * fix(navbar): missing prop * refactor(app-connectors): to useQuery for fetching image regex setting * refactor(app-shell): connectors to useQuery * test(app-shell): fix setup * chore: regenerate lockfile * chore: update react-apollo to 3.0.1 * refactor(connectors): image regex tests to RTL * fix: query mocks for project suspended * fix: pin react-test-renderer to 16.9 * fix(quick-access): update state unless component is unmounting * refactor: componentWillUnmount is not a deprecated lifecycle method * test: cleanup * refactor: renaming based on feedback fix(app-shell): to run useEffect only once in dev mode
* chore: update to react@16.9 (#966) * chore: update to react@16.9 * fix: update lifecyle methods * chore: temporary resolution for react * chore(deps): update dependency @testing-library/react to v9.1.1 (#956) * chore(deps): update dependency @testing-library/react to v8.0.9 * chore: update testing library to 9.1.1 * fix: remove cleanup-after-each hook (automatical now) * refactor: to remove path for act * refactor(app-shell): use react-apollo v3, use more hooks * refactor(app-shell): do not render hooks conditionally * chore: update react deps consistently * refactor(authenticated): do not render hook conditionally * chore: patch jest setup to avoid logging certain warnings on CI * fix: missing prop ref * fix(navbar): missing prop * refactor(app-connectors): to useQuery for fetching image regex setting * refactor(app-shell): connectors to useQuery * test(app-shell): fix setup * chore: regenerate lockfile * chore: update react-apollo to 3.0.1 * refactor(connectors): image regex tests to RTL * fix: query mocks for project suspended * fix: pin react-test-renderer to 16.9 * fix(quick-access): update state unless component is unmounting * refactor: componentWillUnmount is not a deprecated lifecycle method * test: cleanup * refactor: renaming based on feedback fix(app-shell): to run useEffect only once in dev mode
Use react-apollo v3, migrate internal queries to
useQuery
, fix tests.