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

[MM-57710] Convert katex class component to function component #26967

Merged
merged 9 commits into from May 24, 2024

Conversation

marlenekoh
Copy link
Contributor

@marlenekoh marlenekoh commented May 7, 2024

Summary

Migrates ./components/latex_block/latex_block.tsx from Class Component to Function Component

Ticket Link

Fixes #26678

Screenshots

Release Note

NONE

@mm-cloud-bot
Copy link

@marlenekoh: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

I understand the commands that are listed here

@mattermost-build
Copy link
Contributor

Hello @marlenekoh,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

@larkox larkox self-requested a review May 7, 2024 14:29
Copy link
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

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

Great work! Just one minor thing.

webapp/channels/src/components/latex_block/latex_block.tsx Outdated Show resolved Hide resolved
@larkox larkox requested a review from hmhealey May 7, 2024 15:34
@larkox larkox added 2: Dev Review Requires review by a developer 3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review labels May 7, 2024
@unified-ci-app
Copy link
Contributor

unified-ci-app bot commented May 7, 2024

Enterprise tests are not yet completed. You need to wait until Enterprise CI/docker-image status check is successful, before triggering E2E tests.

@mm-cloud-bot mm-cloud-bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed labels May 7, 2024
@marlenekoh
Copy link
Contributor Author

marlenekoh commented May 7, 2024

@larkox thanks for the review! Made the changes.

@marlenekoh marlenekoh changed the title [GH-26678] Convert katex class component to function component [MM-57710] Convert katex class component to function component May 7, 2024
Copy link
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

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

Great work. Thanks!

Copy link
Member

@hmhealey hmhealey left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @marlenekoh!

The code looks good to me, but it looks like the unit tests for this component are broken now. Could you take a look at fixing those? You can run just the test for that one component by running npm test -w channels -- components/latex_block in the webapp folder.

It looks like one of the snapshots is broken because of the component's display name changed, so that one just needs to be updated with -u, but the others seem to be failing because it's not loading Katex any more. I'm not sure if that's because useEffect isn't setting the state correctly or if the way that we're waiting for the async import to happen doesn't work with the functional component though

@marlenekoh
Copy link
Contributor Author

Alright, I will take a look!

@marlenekoh
Copy link
Contributor Author

marlenekoh commented May 19, 2024

@hmhealey the tests for latex component should pass now, please take a look 🙏

  • I had to change the code from shallow() to render() in the latex tests because the useEffect() hook was not running for shallow()
  • set katex options: throwOnError: true so that it can be caught in the except block
  • also added data-testid to make explicit which <div> block was being returned from the component
  • using await screen.findAllByTestId() in the tests to remove this error
     Unexpected console logsWarning: An update to %s inside a test was not wrapped in act(...).
    
     When testing, code that causes React state updates should be wrapped into act(...):
    
     act(() => {
       /* fire events that update state */
     });
     /* assert on the output */
    
     This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act%s,LatexBlock,
    
  • also updated the snapshot for message_html_to_component.test.tsx.

qn: do we want to render the error message or handle the katex.ParseError instead?
https://katex.org/docs/api#handling-errors

@larkox larkox requested a review from hmhealey May 20, 2024 06:56
Copy link
Member

@hmhealey hmhealey left a comment

Choose a reason for hiding this comment

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

Thanks for all the details on what you changed. That makes sense that we'd have to switch to Testing Library for this since Enzyme doesn't even officially support React 17. We really need to get rid of Enzyme one of these days.

As for throwOnError, I didn't realize that that's been false for years at this point since it still seems to render errors like it did originally. I see you reverted that though which is also totally fine. It's definitely something we'll want to look into at some point, but it's not at all a priority.

Overall, this looks good to me!

@hmhealey hmhealey removed the 2: Dev Review Requires review by a developer label May 23, 2024
@yasserfaraazkhan yasserfaraazkhan added the Setup Cloud Test Server Setup an on-prem test server label May 24, 2024
@yasserfaraazkhan
Copy link
Contributor

/e2e-tests

@unified-ci-app
Copy link
Contributor

E2E test triggered successfully for PR #26967. The corresponding commit's status check will be available shortly.

Copy link

E2E test run is starting for commit af9813a586788ae5eb285e9ec006d3715fd49a43.
You can check its progress by either:

Copy link
Contributor

@yasserfaraazkhan yasserfaraazkhan left a comment

Choose a reason for hiding this comment

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

image

@larkox larkox added 4: Reviews Complete All reviewers have approved the pull request and removed 3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review labels May 24, 2024
@larkox larkox merged commit 3812a97 into mattermost:master May 24, 2024
16 checks passed
@mattermost-build mattermost-build removed the Setup Cloud Test Server Setup an on-prem test server label May 24, 2024
@mm-cloud-bot
Copy link

Test server destroyed

@amyblais amyblais added Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation labels May 24, 2024
@marlenekoh marlenekoh deleted the github-26678 branch May 24, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request Changelog/Not Needed Does not require a changelog entry Contributor Docs/Not Needed Does not require documentation release-note-none Denotes a PR that doesn't merit a release note.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert ./components/latex_block/latex_block.tsx from Class Component to Function Component
7 participants