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

fix history dep #59

Merged
merged 3 commits into from
Jul 10, 2023
Merged

fix history dep #59

merged 3 commits into from
Jul 10, 2023

Conversation

ChristopherChudzicki
Copy link
Contributor

@ChristopherChudzicki ChristopherChudzicki commented Jul 7, 2023

Relevant Tickets

#58, mitodl/open-discussions#4115

Description (What does it do?)

This PR:

  1. changes history from a dependency to a peer dependency.
  2. Updates prettier, since we needed to import type { ... } from "history", and import type is not supported by Prettier v1

See code comments.

How should this be tested?

In Open discussions:

git checkout cc/update-course-search-utils
docker compose run --rm watch yarn install # or docker-compose up

Check that search still works.

@@ -8,7 +8,7 @@ import React, {
} from "react"
import { unionWith, eqBy, prop, clone } from "ramda"
import _ from "lodash"
import { History as HHistory } from "history"
import type { History as HHistory } from "history"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

import type statements are removed when Typescript is compiled to Javascript.

A consuming typescript project that uses history v5 will use types directly from history, which provides its own types starting in v5.

A consuming typescript project that uses history v4 will use types from @types/history.

A consuming javascript project will not use types.

@@ -431,11 +431,10 @@ export const useCourseSearch = (
updateUI
} = seachUI
const { activeFacets, sort, ui } = searchParams
const activeFacetsAndSort = useMemo(() => ({ activeFacets, sort, ui }), [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed by prettier v1 -> v2 upgrade.

Comment on lines +77 to +78
"@types/history": "^4.9",
"history": "^4.9 || ^5.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.

The only way that course-search-utils uses history is as a type annotation for the useCourseSearch export, which has a history object as one of its argument. This library does use history directly.

history should be a peer dependency because we want to be sure that course-search-utils and the parent app are using the same version of history. Additionally, it's an optional peer dependency because: if you're not using the useCourseSearch export, you don't need history in your app.

@types/history is optional for the same reason. Additionally, you don't need @types/history if you're not using typescript, or if you're using history v5, which includes its own types.

@abeglova
Copy link
Contributor

Looks like this breaks infinite search for me, specifically when you use the back button to go back to a search that has text.

If you

  1. Search for term
  2. Search for a different term
  3. Use the back button to go back to the first search

the page gets stuck in the loading state and a new search request is never made

@ChristopherChudzicki
Copy link
Contributor Author

This issue @abeglova mentioned was fixed by a yarn install.

As an aside: This should be very safe. There are no non-linting changes to the package code.

@ChristopherChudzicki ChristopherChudzicki merged commit d7dedf7 into main Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants