Skip to content

Conversation

zhyd1997
Copy link

@zhyd1997 zhyd1997 commented Sep 26, 2025

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Partially fixes #26311

Screenshots

Before After
CleanShot 2025-09-27 at 07 45 20@2x ✓ Compiled /app/[appId]/workflow in 15s CleanShot 2025-09-27 at 07 52 29@2x ✓ Compiled /app/[appId]/workflow in 11s

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 dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 26, 2025
Copy link
Contributor

Summary of Changes

Hello @zhyd1997, 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 primarily focuses on enhancing the web application's build and runtime performance through strategic implementation of code splitting and dynamic imports. By deferring the loading of several UI components and the comprehensive Markdown rendering engine, the changes aim to reduce the initial bundle size, leading to faster page loads and a more responsive user experience. Additionally, minor refactorings were performed in the workflow history management to improve type safety and code organization.

Highlights

  • Dynamic Imports for Performance: Several components, including Flowchart, the core ReactMarkdown rendering logic, and SimplePieChart, are now dynamically imported using next/dynamic with ssr: false. This defers their loading until needed on the client-side, significantly reducing the initial JavaScript bundle size and improving application startup performance.
  • Markdown Component Refactoring: The complex ReactMarkdown rendering setup, including its various plugins and component mappings, has been extracted into a new ReactMarkdownWrapper component. This wrapper is then dynamically loaded, isolating its dependencies and further optimizing the main bundle.
  • Workflow History Type Refinement: The WorkflowHistoryEvent enum has been converted to a const object, and a new type WorkflowHistoryEventT has been introduced. This change enhances type safety and consistency in the workflow history management system.
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.

@dosubot dosubot bot added the 💪 enhancement New feature or request label Sep 26, 2025
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 focuses on improving web application performance by dynamically importing heavy components, which is a great approach. The refactoring of the Markdown component and its dependencies into a separate, lazy-loaded wrapper is well-executed. I've added one suggestion to further improve performance by dynamically importing another component.

Comment on lines +11 to +22
import MarkdownForm from '@/app/components/base/markdown-blocks/form'
import Paragraph from '@/app/components/base/markdown-blocks/paragraph'
import ScriptBlock from '@/app/components/base/markdown-blocks/script-block'
import ThinkBlock from '@/app/components/base/markdown-blocks/think-block'
import VideoBlock from '@/app/components/base/markdown-blocks/video-block'
import { customUrlTransform } from './markdown-utils'

import type { FC } from 'react'

import dynamic from 'next/dynamic'

const CodeBlock = dynamic(() => import('@/app/components/base/markdown-blocks/code-block'), { ssr: false })
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For further performance improvement, consider dynamically importing MarkdownForm as well, similar to how CodeBlock is handled. The MarkdownForm component and its dependencies (like DatePicker, TimePicker, Select) can contribute significantly to the bundle size, and forms might not be present in all markdown content. Lazy-loading it would be beneficial.

Suggested change
import MarkdownForm from '@/app/components/base/markdown-blocks/form'
import Paragraph from '@/app/components/base/markdown-blocks/paragraph'
import ScriptBlock from '@/app/components/base/markdown-blocks/script-block'
import ThinkBlock from '@/app/components/base/markdown-blocks/think-block'
import VideoBlock from '@/app/components/base/markdown-blocks/video-block'
import { customUrlTransform } from './markdown-utils'
import type { FC } from 'react'
import dynamic from 'next/dynamic'
const CodeBlock = dynamic(() => import('@/app/components/base/markdown-blocks/code-block'), { ssr: false })
import Paragraph from '@/app/components/base/markdown-blocks/paragraph'
import ScriptBlock from '@/app/components/base/markdown-blocks/script-block'
import ThinkBlock from '@/app/components/base/markdown-blocks/think-block'
import VideoBlock from '@/app/components/base/markdown-blocks/video-block'
import { customUrlTransform } from './markdown-utils'
import type { FC } from 'react'
import dynamic from 'next/dynamic'
const CodeBlock = dynamic(() => import('@/app/components/base/markdown-blocks/code-block'), { ssr: false })
const MarkdownForm = dynamic(() => import('@/app/components/base/markdown-blocks/form'), { ssr: false })

@crazywoola crazywoola self-assigned this Sep 27, 2025
@crazywoola crazywoola requested a review from Copilot September 27, 2025 01:19
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the build performance of the web application's workflow feature by implementing dynamic imports for heavy components and refactoring type definitions to use const assertions instead of enums.

  • Convert enum to const object with type assertion for better tree shaking
  • Add dynamic imports for performance-heavy components like charts, markdown, and mermaid diagrams
  • Refactor markdown component structure to enable code splitting

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
web/app/components/workflow/workflow-history-store.tsx Update type reference to use new const-based type
web/app/components/workflow/hooks/use-workflow-history.ts Convert enum to const object and update type definitions
web/app/components/workflow-app/index.tsx Update import path to more specific hook location
web/app/components/datasets/documents/create-from-pipeline/data-source/local-file/index.tsx Add dynamic import for SimplePieChart component
web/app/components/base/markdown/react-markdown-wrapper.tsx Extract ReactMarkdown logic into separate component with dynamic CodeBlock import
web/app/components/base/markdown/index.tsx Refactor to use dynamic import for ReactMarkdown wrapper
web/app/components/base/markdown-blocks/code-block.tsx Add dynamic import for Flowchart component

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Chore/Refactor] web app build performance improvements
2 participants