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

Frontend dependency updates #5721

Merged

Conversation

tsmock
Copy link
Contributor

@tsmock tsmock commented Apr 19, 2023

This PR intends to make the TM compatible with the defaults of Debian Bookworm. This means that the frontend needs to be compatible with NodeJS 18.x.

In general, the code changes are intended to be limited to compatibility changes. In the event that there needs to be a reformat due to formatting tool updates, those will be in separate commits (to make rebasing onto a new develop HEAD easier).

This PR replaces frontend PRs #5712, #5640, #5586, #5585, #5583, #5540, #5529, #5510, #5474, #5467, and #5177.

This does not update Rapid to v2 -- that will need to be a separate PR.

Total bundle size has decreased from 14.26 MB to 8.07 MB.
main bundle size has decreased from 3.12 MB to 2.56 MB.

  • This can be additionally reduced by lazy-loading the map component

At one point, I had the main bundle size reduced to 700 KB (before I updated the react-scripts to 5.0.1, which required a workaround for facebook/create-react-app#11770 ). Either that update or the workaround caused two bundles to merge; the first with our code, the second with most of the "heavy" modules.

Test runs from #5721
File Test RPi (Node 16, develop) Mac (Node 16, updates) Mac (Node 18, updates)
src/components/projectCard/tests/dueDateBox.test.js test DueDate › with tooltip message     1
src/components/projectDetail/tests/questionsAndComments.test.js test if QuestionsAndComments component › renders tabs for writing and previewing comments   1 1
src/components/projectDetail/tests/shareButton.test.js test if shareButton › render open corresponding window popup     1
src/components/projectDetail/tests/shareButton.test.js test if shareButton › render shareButton for project with id 1     1
src/components/taskSelection/tests/actionSidebars.test.js Appearance of unsaved map changes to be dealt with while mapping › when splitting a task   2 1
src/components/taskSelection/tests/actionSidebars.test.js Appearance of unsaved map changes to be dealt with while mapping › when submitting a task     1
src/components/taskSelection/tests/actionSidebars.test.js Completion Tab for Validation › should update status and comments for multiple tasks   1  
src/components/taskSelection/tests/contributions.test.js Contributions › clean user selection if we click on the selected tasks of the user 1    
src/components/taskSelection/tests/contributions.test.js Contributions › render users, links, and 1 1 1
src/components/taskSelection/tests/index.test.js Contributions › should clear text when close icon is clicked 3    
src/components/taskSelection/tests/index.test.js Contributions › should select tasks mapped by the selected user 10    
src/components/taskSelection/tests/index.test.js Contributions › should select tasks validated by the selected user 10    
src/components/taskSelection/tests/index.test.js Contributions › should sort tasks by their task number 10    
src/components/taskSelection/tests/taskActivity.test.js TaskHistory › renders the task history comments and activities for a given project   1 1
src/components/taskSelection/tests/taskList.test.js Task Item › should display task detail modal   1 1
src/components/tests/selectAll.test.js SelectAll › unactive when clicked select all elements     1
src/views/tests/interests.test.js Edit Interest › should hide the save button on click     1
src/views/tests/interests.test.js Edit Interest › should return input text value to default when cancel button is clicked     1
src/views/tests/management.test.js Management Page Overview Section › should list projects and teams fetched 2    
src/views/tests/project.test.js CreateProject renders ProjectCreate   1  
src/views/tests/project.test.js Project Detail Page › should render component details 10 1  
src/views/tests/projectStats.test.js ProjectStats dashboard › fetch urls and render sections title   1 2
src/views/tests/taskSelection.test.js Random Task Selection › should not change the button text to map selected task when user selects a task for mapping 10    
src/views/tests/taskSelection.test.js Task Selection Page › should change the button text to map another task when user selects a task for validation but the user level is not met 7    
src/views/tests/taskSelection.test.js Task Selection Page › should change the button text to map selected task when user selects a task 10 1 1
src/views/tests/taskSelection.test.js Task Selection Page › should change the button text to validate selected task 10 1 1
src/views/tests/taskSelection.test.js Task Selection Page › should filter the task list by search query 8 2 1
src/views/tests/teams.test.js Edit Team › should display default details of the team before editing     2
src/views/tests/userDetail.test.js User Detail Component › should render detail for the child components   1 1

[1] bundleSizes.zip

@tsmock tsmock force-pushed the chore/frontend-dependency-cleanup branch 2 times, most recently from 3398ff9 to 7450a7a Compare April 20, 2023 20:44
@tsmock tsmock marked this pull request as ready for review April 20, 2023 20:45
Copy link
Contributor

@HelNershingThapa HelNershingThapa left a comment

Choose a reason for hiding this comment

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

I have reviewed most of the changes overall and find them satisfactory. I have provided my comments where I felt there was room for improvement or further attention. Great job on addressing the annoying warnings across the app! I can't help but add a little levity here:
"Knock, knock."
"Who's there?"
"Warnings."
"Warnings who?"
"No warnings because Taylor has squashed them all!"

It's fantastic to see most of those warnings disappear. There are currently some failing test cases in the codebase that requires revision. I'd like to reassess the modifications when it's rebased to develop. Thanks.

EDIT:
The image in the testimonial section on the landing page is not displayed.
testimonial-land

frontend/package.json Outdated Show resolved Hide resolved
frontend/package.json Outdated Show resolved Hide resolved
frontend/package.json Outdated Show resolved Hide resolved
frontend/package.json Show resolved Hide resolved
frontend/package.json Outdated Show resolved Hide resolved
frontend/src/utils/polyfill.js Show resolved Hide resolved
frontend/src/components/footer/styles.scss Outdated Show resolved Hide resolved
frontend/src/components/projectDetail/styles.scss Outdated Show resolved Hide resolved
scales: { xAxes: [{ type: 'time', time: { unit: unit } }] },
scales: {
y: { ticks: { beginAtZero: true } },
x: { type: 'time', time: { unit: unit }, adapters: { date: { locale: enUS } } },
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to be a noticeable difference in the appearance of the chart and units before and after the change.

Before:
contrib-before

After:
contrib-after

Furthermore, it appears that there is a new addition to the chart tooltip, displaying the time. Previously, the time was not included in the tooltip.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't consider this -- I was testing against a local DB, so I had very few data points. The problem here is that the latter is more accurate when showing when contributions occurred relative to other data points. I don't know who implemented the original timeline, but we might want to loop them in for this conversation. I can see it going either way. There is a timeseries type we can use if the original plot was the intended behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have knowledge of the original timeline implementation. @ramyaragupathy, I'm looping you into this conversation. You might have more insights or context that can help us make an informed decision.

Copy link
Member

Choose a reason for hiding this comment

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

@HelNershingThapa @tsmock - monthly view would work only for projects that are running for a longer time, for ones that have been active for only a week or so would the x axis automatically be using date instead of month? Ideally it will be good to have a toggle between month and date view for the chart. For now we can stick to dates instead of months for the x-axis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pulled the fixes for the console warnings out into #5964.

frontend/package.json Show resolved Hide resolved
@tsmock
Copy link
Contributor Author

tsmock commented May 15, 2023

Great job on addressing the annoying warnings across the app! I can't help but add a little levity here: "Knock, knock." "Who's there?" "Warnings." "Warnings who?" "No warnings because Taylor has squashed them all!"

I haven't hit all the warnings. Some would require significant changes (for example, there is a warning on the project list about <a> inside <a>, IIRC).

It's fantastic to see most of those warnings disappear. There are currently some failing test cases in the codebase that requires revision. I'd like to reassess the modifications when it's rebased to develop. Thanks.

Yep. I had them all passing before my last rebase, and was going to work through them this week.

EDIT: The image in the testimonial section on the landing page is not displayed.

Thanks for noticing. I'll double check and see what happened. I don't recall removing any images/image code.

@HelNershingThapa
Copy link
Contributor

Thanks for noticing. I'll double check and see what happened. I don't recall removing any images/image code.

I think I ran into the same problem when upgrading to React 18. I was able to resolve it with b7ff508.

@tsmock tsmock force-pushed the chore/frontend-dependency-cleanup branch from 7edbab9 to 3af2c03 Compare May 15, 2023 17:56
@HelNershingThapa
Copy link
Contributor

HelNershingThapa commented May 16, 2023

The test execution using fetch generates numerous warnings that indicate a captured request without a corresponding request handler in the MSW library. Here's the specific warning message:

console.warn
    [MSW] Warning: captured a request without a matching request handler:
    
      • GET http://localhost/undefined
    
    If you still wish to intercept this unhandled request, please create a request handler for it.
    Read more: https://mswjs.io/docs/getting-started/mocks

      at Object.warn (node_modules/msw/src/utils/internal/devUtils.ts:17:11)
      at applyStrategy (node_modules/msw/src/utils/request/onUnhandledRequest.ts:208:18)
      at onUnhandledRequest (node_modules/msw/src/utils/request/onUnhandledRequest.ts:233:3)
      at handleRequest (node_modules/msw/src/utils/handleRequest.ts:80:5)
      at node_modules/msw/src/node/SetupServerApi.ts:69:24

No warning was encountered when testing a component that utilizes Axios for data fetching. It seems likely that the warnings are associated with MSW's specific handling mechanisms for the native fetch API in Node.js 18.

EDIT: MSW will ship with Node.js 18+ support with MSW v2.0 as mentioned here mswjs/msw#1388 (comment).

@tsmock tsmock force-pushed the chore/frontend-dependency-cleanup branch from 7f91467 to 5377f20 Compare May 17, 2023 21:05
@eternaltyro eternaltyro self-assigned this May 23, 2023
@tsmock tsmock force-pushed the chore/frontend-dependency-cleanup branch 2 times, most recently from 91ecdad to dbec7f5 Compare May 24, 2023 15:09
@tsmock
Copy link
Contributor Author

tsmock commented May 24, 2023

For the MSW issue, I did a bit of debugging.

    [MSW] Warning: captured a request without a matching request handler:
    
      • GET http://localhost/undefined

It turns out this is a problem from the @mswjs/interceptors package (we are currently using 0.17.9). The code used expects the input to either be a string or have a url field (see v0.17.8/src/interceptors/fetch/index.ts). Our current code calls fetch with URL objects, which are not strings and do not have a url field.

This is fixed in later versions of @mswjs/interceptors (starting in v0.18.0). We would need to update msw to their next release.

The remaining tests that are failing are due to timeout issues, and are not very consistent. Should I increase the timeouts for them?

@HelNershingThapa
Copy link
Contributor

I find it puzzling that this seemingly simple test takes longer than the 5-second timeout. Because the test appears to be a straightforward simple one, as it seeks to verify the successful opening of a dialog with specific text and expects the dialog to close upon clicking the close button.

Despite that, I'm open to the notion of increasing the timeouts for these specific tests. I've also noticed some of these test cases failing in my local development setup but passing in the CircleCI ones. This discrepancy between the environments adds another layer of complexity to the situation.

@tsmock
Copy link
Contributor Author

tsmock commented May 24, 2023

It would be a lot easier if it was consistent. I've had tests fail and then pass, only to fail again later.

I think it is probably related to a greater usage of React.lazy and React.suspense (specifically related to splitting translations out of the main bundle).

@HelNershingThapa
Copy link
Contributor

If that were the case, shouldn't a lot of these test cases fail?

@tsmock
Copy link
Contributor Author

tsmock commented May 24, 2023

That would be intuitive. However, that is the only thing that I saw in common when I was spot checking the failing tests. I'll drop the timeouts I added in some commits and see if I can otherwise fix the issue (maybe I can make a mock that will fix the issue).

EDIT: Nevermind. Both of the tests that failed when I dropped some timeout changes had CommentInputField in common as well.

@tsmock tsmock force-pushed the chore/frontend-dependency-cleanup branch from dbec7f5 to 1ff6121 Compare May 25, 2023 14:36
@HelNershingThapa
Copy link
Contributor

HelNershingThapa commented May 25, 2023

I noticed that the circle layer for the tasks centroid on the project detail page does not navigate to the task selection page when clicked. This functionality appears to be broken.

https://github.com/facebook/OSM-HOT-Tasking-Manager/blob/1ff61218946e43cec7f66c65dc225ac8410b7fa8/frontend/src/components/taskSelection/map.js#L399-L400

EDIT: Something unusual is happening here: when you press the back button on the browser numerous times, you'll find that the app did navigate to the intended route, indicating that the on-click event is being triggered multiple times. We can eliminate the problem by removing the relative navigation and instead using the full path '/projects/:id/tasks,' but the back functionality still won't work.

@tsmock
Copy link
Contributor Author

tsmock commented May 25, 2023

I checked on the tasks-stage instance, and I had to click back 10 times to go back a page.

As far as going to the wrong page, here is the calls that leads to the incorrect behavior:

  1. /projects/:id + ./tasks -> /projects/:id/tasks
  2. /projects/:id/tasks +./tasks -> /projects/:id/tasks/tasks
  3. /projects/:id/tasks/tasks + ./tasks -> /tasks
  4. /tasks + ./tasks -> /tasks

The current state of code probably triggers the call navigate calls another 6 times.

EDIT: I've made a PR for this at #5962.

@tsmock tsmock force-pushed the chore/frontend-dependency-cleanup branch from 13def81 to e9c741a Compare May 31, 2023 12:47
@tsmock
Copy link
Contributor Author

tsmock commented May 31, 2023

I think I'm going to start splitting some of the changes out. Specifically,

@tsmock tsmock force-pushed the chore/frontend-dependency-cleanup branch from e9c741a to b90a6dc Compare June 2, 2023 12:51
tsmock and others added 17 commits April 16, 2024 08:16
Signed-off-by: Taylor Smock <tsmock@meta.com>
quickstart.js has the same spacing as it had previously (which comes
from the empty <p/>).

Signed-off-by: Taylor Smock <tsmock@meta.com>
* `Sign Up` button
* comment boxes
* actionsForm.js (mostly buttons)

Signed-off-by: Taylor Smock <tsmock@meta.com>
This reduces the main chunk size from 3.65 MB to 2.56 MB.
Something about the commit "Use CRACO to workaround CRA #11770" caused
several large components to be added to the main.*.js bundle.

All suspense elements are *roughly* the same size as the expected text
editor box, plus or minus a row.

Signed-off-by: Taylor Smock <tsmock@meta.com>
* Avoid default imports in ReactJS
  There were quite a few files where we imported react, but didn't
  actually use it.
* Use non-default imports where possible
* Use named imports where possible

Signed-off-by: Taylor Smock <tsmock@meta.com>
Signed-off-by: Taylor Smock <tsmock@meta.com>
Signed-off-by: Taylor Smock <tsmock@meta.com>
… handling

Signed-off-by: Taylor Smock <tsmock@meta.com>
Signed-off-by: Taylor Smock <tsmock@meta.com>
Signed-off-by: Taylor Smock <tsmock@meta.com>
Signed-off-by: Taylor Smock <tsmock@meta.com>
…g to finish

Signed-off-by: Taylor Smock <tsmock@meta.com>
Signed-off-by: Taylor Smock <tsmock@meta.com>
Signed-off-by: Taylor Smock <tsmock@meta.com>
This should fix some timeout issues.
Signed-off-by: Taylor Smock <tsmock@meta.com>
@tsmock tsmock force-pushed the chore/frontend-dependency-cleanup branch from 826ed49 to 67ad269 Compare April 16, 2024 14:17
Copy link

sonarcloud bot commented Apr 16, 2024

Quality Gate Passed Quality Gate passed

Issues
11 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@varun2948
Copy link
Contributor

@ramyaragupathy I think we are good to go on this PR and we are ready to merge it into staging for now and will create another PR fixing the osm download most probably today and will let manjita test it.
Cc: @manjitapandey, @royallsilwallz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file scope: frontend scope: infrastructure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants