fix(dify-ui): support data-tone styling for Answer node buttons - #38967
Draft
snowmint wants to merge 2 commits into
Draft
fix(dify-ui): support data-tone styling for Answer node buttons#38967snowmint wants to merge 2 commits into
snowmint wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Fixes #<issue number>.Summary
Fixes #38895
This PR adds support for the
data-toneattribute on buttons rendered from Answer node Markdown/HTML content.Previously, the following button was rendered using the default primary styling instead of the destructive styling:
The underlying Dify UI
Buttoncomponent already supports destructive styling through:However, the Answer node Markdown rendering pipeline did not preserve or forward
data-toneto thetoneprop.The issue occurred in two places:
dataTonewas not included in the Streamdown sanitizer allowlist, sodata-tonecould be removed during HTML sanitization.MarkdownButtonreaddataVariantanddataSize, but did not readdataToneor pass it to the Dify UIButtoncomponent.This PR:
dataToneto the allowed attributes for Markdown<button>elements.node.properties.dataToneinMarkdownButton.Buttonthrough thetoneprop.defaultdestructivedata-toneis omitted.data-variant="warning"behaviorDuring investigation,
data-variant="warning"was also tested as a possible way to render a destructive or warning-style button.This approach is outdated and is not supported by the current Dify UI
Buttoncomponent.The currently supported variants are:
primarysecondarysecondary-accenttertiaryghostghost-accentDestructive styling is implemented by combining a supported variant with the
destructivetone:Therefore, this PR does not add or restore a
warningvariant. The supported Answer node syntax is:Documentation
The current supported-tags documentation still lists behavior that no longer fully matches the current implementation:
https://docs.dify.ai/en/cloud/use-dify/nodes/template#supported-tags
A related documentation update may be required to clarify:
data-variantvalues.data-variant="warning"is unsupported.data-tonevalues.Screenshots
data-tone="destructive"was ignored, and the button was rendered using the normal primary style.Before: data-tone ignored
data-variant="primary"anddata-tone="destructive"are provided.After: destructive tone applied
Additional verification
The UI test page verifies the supported Button tone combinations:
Test plan
Automated tests
Frontend validation
Manual verification
Add the following content to an Answer node:
Run the app in Preview.
Verify that:
stop.data-toneretain their existing appearance.data-variant="warning"is not required and does not act as a supported variant.Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint goods.pnpm exec vp stagedresulted in an error. I manually verified that the changes follow the existing code style and ran the relevant spec tests to validate the logic.