[PR #26696] fix: issue w/ timepicker #31518

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

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

State: closed
Merged: Yes


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

This pull request refactors and improves the TimePicker component to better handle both Dayjs objects and string values for the value prop, ensuring robust type handling, preventing unnecessary updates, and improving internal state management. The changes also enhance the reliability of time selection and formatting logic.

Type handling improvements:

  • Updated the TimePickerProps type to allow the value prop to accept either a Dayjs object or a string, improving flexibility for consumers of the component.
  • Added helper functions isDayjsObject and toDayjs to safely check and convert values to Dayjs objects, ensuring consistent internal handling of time values. [1] [2]

State management and update logic:

  • Refactored initialization and updates of the selectedTime state to use the new helper functions, and added logic to track previous value and timezone to avoid unnecessary updates or onChange calls. This prevents redundant renders and ensures correct synchronization with parent components. [1] [2]

User interaction and formatting:

  • Improved event handlers for time selection (handleSelectHour, handleSelectMinute, handleSelectPeriod, handleSelectCurrentTime, handleConfirm) to use a safe getter for the time object and to avoid unnecessary onChange calls. Also, ensured that all onChange calls are safely wrapped in setTimeout to prevent render loops. [1] [2]
  • Refactored display and placeholder formatting logic to use the new type-safe formatting helpers, ensuring that both string and Dayjs values are correctly formatted for display.

Screenshots

Before After
... image

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
**Original Pull Request:** https://github.com/langgenius/dify/pull/26696 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This pull request refactors and improves the `TimePicker` component to better handle both `Dayjs` objects and string values for the `value` prop, ensuring robust type handling, preventing unnecessary updates, and improving internal state management. The changes also enhance the reliability of time selection and formatting logic. **Type handling improvements:** * Updated the `TimePickerProps` type to allow the `value` prop to accept either a `Dayjs` object or a string, improving flexibility for consumers of the component. * Added helper functions `isDayjsObject` and `toDayjs` to safely check and convert values to `Dayjs` objects, ensuring consistent internal handling of time values. [[1]](diffhunk://#diff-c21389295a1956d5d6f9958bf7cd914549d16fc5300d47904cf6df7db290dd15R2) [[2]](diffhunk://#diff-c21389295a1956d5d6f9958bf7cd914549d16fc5300d47904cf6df7db290dd15R17-R33) **State management and update logic:** * Refactored initialization and updates of the `selectedTime` state to use the new helper functions, and added logic to track previous `value` and `timezone` to avoid unnecessary updates or onChange calls. This prevents redundant renders and ensures correct synchronization with parent components. [[1]](diffhunk://#diff-c21389295a1956d5d6f9958bf7cd914549d16fc5300d47904cf6df7db290dd15L31-R54) [[2]](diffhunk://#diff-c21389295a1956d5d6f9958bf7cd914549d16fc5300d47904cf6df7db290dd15R65-R110) **User interaction and formatting:** * Improved event handlers for time selection (`handleSelectHour`, `handleSelectMinute`, `handleSelectPeriod`, `handleSelectCurrentTime`, `handleConfirm`) to use a safe getter for the time object and to avoid unnecessary onChange calls. Also, ensured that all onChange calls are safely wrapped in setTimeout to prevent render loops. [[1]](diffhunk://#diff-c21389295a1956d5d6f9958bf7cd914549d16fc5300d47904cf6df7db290dd15L64-R128) [[2]](diffhunk://#diff-c21389295a1956d5d6f9958bf7cd914549d16fc5300d47904cf6df7db290dd15R145-R196) * Refactored display and placeholder formatting logic to use the new type-safe formatting helpers, ensuring that both string and `Dayjs` values are correctly formatted for display. ## Screenshots | Before | After | |--------|-------| | ... | <img width="758" height="714" alt="image" src="https://github.com/user-attachments/assets/00ef5190-5382-4166-bd3a-c9712f038071" /> | ## Checklist - [ ] 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!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:49:37 -05:00
yindo closed this issue 2026-02-21 20:49:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31518