Skip to content

Conversation

@majiayu000
Copy link
Contributor

Summary

Fixes #31522

Remove the outdated react-papaparse package and replace with native papaparse library. This provides better React 19 compatibility and reduces bundle size.

Changes

  • Add utils/csv.ts with downloadCSV and parseCSV utilities
  • Update all CSV download/reader components to use new utilities
  • Update tests to mock the new utilities
  • Remove react-papaparse dependency, add papaparse and @types/papaparse

Files Changed

  • web/utils/csv.ts - New CSV utility functions
  • web/app/components/share/text-generation/run-batch/csv-download/index.tsx
  • web/app/components/share/text-generation/run-batch/csv-reader/index.tsx
  • web/app/components/share/text-generation/run-batch/res-download/index.tsx
  • web/app/components/app/annotation/header-opts/index.tsx
  • web/app/components/app/annotation/batch-add-annotation-modal/csv-downloader.tsx
  • web/app/components/datasets/documents/detail/batch-modal/csv-downloader.tsx
  • Updated corresponding test files

Screenshots

Before After
Uses react-papaparse hooks Uses native papaparse with utility functions

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jan 26, 2026
@github-actions github-actions bot added the web This relates to changes on the web. label Jan 26, 2026
@dosubot dosubot bot added the refactor label Jan 26, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @majiayu000, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the application's CSV handling by migrating from the react-papaparse library to the more lightweight and React 19 compatible native papaparse library. The change centralizes CSV operations into new utility functions, leading to a cleaner codebase, reduced bundle size, and improved maintainability across various components that interact with CSV data.

Highlights

  • Dependency Migration: Replaced the react-papaparse package with the native papaparse library to improve React 19 compatibility and reduce bundle size.
  • New CSV Utilities: Introduced a new utility file web/utils/csv.ts containing downloadCSV and parseCSV functions for centralized CSV handling.
  • Component Updates: All existing CSV download and reader components have been updated to utilize the newly created downloadCSV and parseCSV utilities.
  • Test Refactoring: Corresponding test files have been updated to mock and verify the behavior of the new CSV utility functions instead of the react-papaparse hooks.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors CSV handling across the application by removing the react-papaparse library. It introduces a new web/utils/csv.ts utility file that encapsulates downloadCSV and parseCSV functionalities using the underlying papaparse library. All components previously using react-papaparse hooks for downloading CSV templates, exporting data, and reading uploaded CSVs have been updated to utilize these new utility functions. Corresponding test files have been adjusted to mock the new downloadCSV and parseCSV utilities. Review comments suggest improving a test mock for parseCSV to be more dynamic, removing redundant variables in test mocks, and eliminating an unnecessary type cast in the new parseCSV utility function.

{children}
</div>
)
let _lastCSVDownloaderProps: Record<string, unknown> | undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The _lastCSVDownloaderProps variable is declared but not used in the new mock implementation. Since vi.fn() automatically tracks calls and arguments, this variable is redundant and can be removed for cleaner code.

const mockDownloadCSV = vi.fn((...args: unknown[]) => {

mockCSVDownloader.mockClear()
lastCSVDownloaderProps = undefined
mockDownloadCSV.mockClear()
_lastCSVDownloaderProps = undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the previous comment, _lastCSVDownloaderProps = undefined is redundant here. mockDownloadCSV.mockClear() is sufficient to reset the mock's state.

    mockDownloadCSV.mockClear()

web/utils/csv.ts Outdated
): void {
const { header = false, skipEmptyLines = true, complete } = options || {}

Papa.parse(file as unknown as string, {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The file parameter is typed as File, but it's cast to unknown as string before being passed to Papa.parse. Papa.parse can directly accept a File object. The cast to string is unnecessary and could be misleading. It's better to pass the File object directly.

Suggested change
Papa.parse(file as unknown as string, {
Papa.parse(file, {

@hyoban
Copy link
Member

hyoban commented Jan 29, 2026

Can you help resolve the conflict?

@hyoban hyoban added the status: awaiting response Issues waiting for a reply from the OP or another party label Jan 29, 2026
majiayu000 and others added 3 commits January 29, 2026 19:45
Remove the outdated react-papaparse package and replace with native
papaparse library. This provides better React 19 compatibility and
reduces bundle size.

Changes:
- Add utils/csv.ts with downloadCSV and parseCSV utilities
- Update all CSV download/reader components to use new utilities
- Update tests to mock the new utilities
- Remove react-papaparse dependency, add papaparse

Fixes langgenius#31522

Signed-off-by: majiayu000 <[email protected]>
…index.spec.tsx

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Remove redundant _lastCSVDownloaderProps variable in test
- Use cleaner type assertion (as any) for Papa.parse
- Simplify mock function implementation
- Add eslint-disable for necessary type cast

Signed-off-by: majiayu000 <[email protected]>
@majiayu000 majiayu000 force-pushed the refactor/remove-react-papaparse-31522 branch from 117d956 to 882b89f Compare January 29, 2026 11:56
@hyoban hyoban removed the status: awaiting response Issues waiting for a reply from the OP or another party label Jan 29, 2026
@hyoban hyoban requested a review from CodingOnStar as a code owner January 30, 2026 07:08
@hyoban hyoban requested a review from Yessenia-d as a code owner January 30, 2026 07:08
@majiayu000
Copy link
Contributor Author

这ci真难解决卧槽。。。

@hyoban
Copy link
Member

hyoban commented Jan 30, 2026

It's okay to skip the test for now. It should be fixed in #31729. I will look at it after then.

The Promise.resolve().then() approach caused timing issues with React
Testing Library's waitFor, as microtasks execute at different points
in the event loop compared to macrotasks (setTimeout).

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size:XL This PR changes 500-999 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor/Chore] Remove react-papaparse

2 participants