[PR #26249] [Chore/Refactor] Add missing 'type' attribute on 'button' components #31367

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

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

State: closed
Merged: Yes


Overview

This PR adds missing type="button" attributes to button elements across the web application to prevent unwanted form submission behavior.

Problem

According to the MDN documentation, button elements without an explicit type attribute default to type="submit". This means that buttons intended for UI interactions can accidentally trigger form submissions when clicked, potentially causing:

  • Unexpected page reloads
  • Loss of current application state
  • Unintended data submission

Solution

Added type="button" attributes to all interactive UI buttons that are not intended for form submission. This explicitly declares their purpose and prevents the default submit behavior.

Files Changed

Updated 32 files across the codebase, including:

  • App management components: new-app-card.tsx, app-card.tsx
  • Workflow UI components: Schema editor buttons, tracing panel controls
  • Base UI components: Date pickers, audio controls, pagination, theme selector
  • Demo and test files: Service demo buttons and test components

Example Changes

Before:

<button className="..." onClick={handleClick}>
  Click me
</button>

After:

<button type="button" className="..." onClick={handleClick}>
  Click me
</button>

Testing

  • All existing tests pass (232 tests across 18 suites)
  • Button component tests specifically verified (18/18 passing)
  • No linting errors introduced
  • No functionality regressions detected

Impact

  • Zero breaking changes - all existing functionality preserved
  • Improved UX - prevents accidental form submissions
  • Better accessibility - explicit button behavior declaration
  • Follows web standards - aligns with MDN best practices

Resolves the issue by ensuring all interactive buttons have proper type declarations while maintaining full backward compatibility.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Chore/Refactor] Add missing 'type' attribute on 'button' component</issue_title>
<issue_description>### Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for refactoring, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Description

add type="button"

Motivation

If your buttons are not for submitting form data to a server, be sure to set their type attribute to button. Otherwise, they will try to submit form data and to load the (nonexistent) response, possibly destroying the current state of the document.

Additional Context

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#notes</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes langgenius/dify#25223

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

**Original Pull Request:** https://github.com/langgenius/dify/pull/26249 **State:** closed **Merged:** Yes --- ## Overview This PR adds missing `type="button"` attributes to button elements across the web application to prevent unwanted form submission behavior. ## Problem According to the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#notes), button elements without an explicit `type` attribute default to `type="submit"`. This means that buttons intended for UI interactions can accidentally trigger form submissions when clicked, potentially causing: - Unexpected page reloads - Loss of current application state - Unintended data submission ## Solution Added `type="button"` attributes to all interactive UI buttons that are not intended for form submission. This explicitly declares their purpose and prevents the default submit behavior. ## Files Changed Updated 32 files across the codebase, including: - **App management components**: `new-app-card.tsx`, `app-card.tsx` - **Workflow UI components**: Schema editor buttons, tracing panel controls - **Base UI components**: Date pickers, audio controls, pagination, theme selector - **Demo and test files**: Service demo buttons and test components ## Example Changes Before: ```tsx <button className="..." onClick={handleClick}> Click me </button> ``` After: ```tsx <button type="button" className="..." onClick={handleClick}> Click me </button> ``` ## Testing - ✅ All existing tests pass (232 tests across 18 suites) - ✅ Button component tests specifically verified (18/18 passing) - ✅ No linting errors introduced - ✅ No functionality regressions detected ## Impact - **Zero breaking changes** - all existing functionality preserved - **Improved UX** - prevents accidental form submissions - **Better accessibility** - explicit button behavior declaration - **Follows web standards** - aligns with MDN best practices Resolves the issue by ensuring all interactive buttons have proper type declarations while maintaining full backward compatibility. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[Chore/Refactor] Add missing 'type' attribute on 'button' component</issue_title> > <issue_description>### Self Checks > > - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). > - [x] This is only for refactoring, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). > - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. > - [x] I confirm that I am using English to submit this report, otherwise it will be closed. > - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) > - [x] Please do not modify this template :) and fill in all the required fields. > > ### Description > > add type="button" > > ### Motivation > > If your buttons are not for submitting form data to a server, be sure to set their type attribute to button. Otherwise, they will try to submit form data and to load the (nonexistent) response, possibly destroying the current state of the document. > > ### Additional Context > > https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#notes</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> Fixes langgenius/dify#25223 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
yindo added the pull-request label 2026-02-21 20:49:20 -05:00
yindo closed this issue 2026-02-21 20:49: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#31367