[PR #20177] Refactor/markdown component split #29327

Closed
opened 2026-02-21 20:45:20 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/20177

State: closed
Merged: Yes


Summary

Refactor markdown component to improve code organization and maintainability. This PR focuses on modularizing the markdown component structure and fixing linting errors.

Motivation:
The current markdown.tsx file has grown quite large (500+ lines) and contains multiple complex components. This refactoring improves code organization by:

  1. Splitting components into separate modules
  2. Fixing existing linting errors (removing unnecessary semicolons and brackets)
  3. Optimizing ECharts rendering performance in CodeBlock component

Changes Made:

  1. Restructured file organization:

    • Moved markdown.tsx to markdown/index.tsx
    • Created markdown-blocks/ directory for individual block components
    • Extracted utility functions to markdown-utils.ts
    • Separated ErrorBoundary into its own file
  2. Created separate files for block components:

    • code-block.tsx: Code syntax highlighting and ECharts rendering
    • pre-code.tsx: Pre-formatted code blocks
    • video-block.tsx: Video embedding
    • audio-block.tsx: Audio player
    • script-block.tsx: Script handling
    • paragraph.tsx: Text paragraphs
    • img.tsx: Image rendering
    • link.tsx: Link handling

Testing Required

Critical Areas Needing Testing:

  1. Markdown Rendering Scenarios:

    • Basic markdown text rendering
    • Code blocks with different languages
    • ECharts rendering and interactions
    • Image display and handling
    • Link functionality
    • Video and audio playback
    • SVG rendering
    • Error boundary functionality
  2. Import Path Verification:

    • Verify all components using @/app/components/base/markdown still work
    • Check for any broken imports in the codebase
    • Validate barrel file exports
  3. Performance Testing:

    • ECharts rendering performance
    • Memory usage with multiple instances
    • Load time impact

Risks and Mitigations

  • Risk: Some import paths might be missed during refactoring
    • Mitigation: Need comprehensive testing across the application
  • Risk: Performance regression in certain scenarios
    • Mitigation: Performance testing needed before merge

Next Steps

  1. Complete thorough testing of all components
  2. Add automated tests for critical functionality
  3. Document any found issues or edge cases
  4. Consider further code splitting based on testing results

Screenshots

Before After
N/A (Code structure changes) N/A (Code structure changes)

follow up #https://github.com/langgenius/dify/pull/20161

Checklist

  • This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/- [ ] 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 dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Help Needed

  • Need team members to help test different scenarios
  • Looking for feedback on component organization
  • Performance testing assistance welcome
**Original Pull Request:** https://github.com/langgenius/dify/pull/20177 **State:** closed **Merged:** Yes --- # Summary Refactor markdown component to improve code organization and maintainability. This PR focuses on modularizing the markdown component structure and fixing linting errors. **Motivation:** The current `markdown.tsx` file has grown quite large (500+ lines) and contains multiple complex components. This refactoring improves code organization by: 1. Splitting components into separate modules 2. Fixing existing linting errors (removing unnecessary semicolons and brackets) 3. Optimizing ECharts rendering performance in CodeBlock component **Changes Made:** 1. Restructured file organization: - Moved `markdown.tsx` to `markdown/index.tsx` - Created `markdown-blocks/` directory for individual block components - Extracted utility functions to `markdown-utils.ts` - Separated `ErrorBoundary` into its own file 2. Created separate files for block components: - `code-block.tsx`: Code syntax highlighting and ECharts rendering - `pre-code.tsx`: Pre-formatted code blocks - `video-block.tsx`: Video embedding - `audio-block.tsx`: Audio player - `script-block.tsx`: Script handling - `paragraph.tsx`: Text paragraphs - `img.tsx`: Image rendering - `link.tsx`: Link handling # Testing Required **Critical Areas Needing Testing:** 1. Markdown Rendering Scenarios: - [ ] Basic markdown text rendering - [ ] Code blocks with different languages - [ ] ECharts rendering and interactions - [ ] Image display and handling - [ ] Link functionality - [ ] Video and audio playback - [ ] SVG rendering - [ ] Error boundary functionality 2. Import Path Verification: - [ ] Verify all components using `@/app/components/base/markdown` still work - [ ] Check for any broken imports in the codebase - [ ] Validate barrel file exports 3. Performance Testing: - [ ] ECharts rendering performance - [ ] Memory usage with multiple instances - [ ] Load time impact # Risks and Mitigations - Risk: Some import paths might be missed during refactoring - Mitigation: Need comprehensive testing across the application - Risk: Performance regression in certain scenarios - Mitigation: Performance testing needed before merge # Next Steps 1. Complete thorough testing of all components 2. Add automated tests for critical functionality 3. Document any found issues or edge cases 4. Consider further code splitting based on testing results # Screenshots | Before | After | |--------|-------| | N/A (Code structure changes) | N/A (Code structure changes) | follow up #https://github.com/langgenius/dify/pull/20161 # Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/- [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] 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 `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods # Help Needed - Need team members to help test different scenarios - Looking for feedback on component organization - Performance testing assistance welcome
yindo added the pull-request label 2026-02-21 20:45:20 -05:00
yindo closed this issue 2026-02-21 20:45:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29327