Fixed issue where sometimes a timezone object is passed not a string …#25
Conversation
…as the typehint lays out. Also handle racecondition when syncing dates and update post run in wrong order
WalkthroughThis set of changes updates three files related to event date management in a WordPress block. In Estimated code review effort3 (~45 minutes) ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/blocks/event-info/index.js (2)
327-367: Excellent refactoring of the post save synchronization logicThe subscription-based approach provides better control over the save lifecycle by detecting state transitions and handling asynchronous date saves properly. The two-step save process ensures event dates are reliably persisted.
Consider using optional chaining for better safety:
- if (currentSaving && !currentAutosaving && !wasSaving && dateManagerState?.getCurrentDates()?.dates) { + if (currentSaving && !currentAutosaving && !wasSaving && dateManagerState?.getCurrentDates?.()?.dates) {
370-385: Good optimization for attribute synchronizationThe deep comparison using JSON.stringify prevents unnecessary attribute updates and re-renders. Adding
attributes.eventDatesto the dependency array ensures proper reactivity.Note: For large date arrays, consider using a more efficient deep comparison method like lodash's
isEqualwhich is already imported in this file.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/blocks/event-info/event-manager.js(3 hunks)src/blocks/event-info/index.js(4 hunks)src/event-functions.php(1 hunks)
🧠 Learnings (4)
📓 Common learnings
Learnt from: gin0115
PR: a8cteam51/simple-events#17
File: src/blocks/event-info/index.js:82-98
Timestamp: 2025-06-17T12:10:45.329Z
Learning: In src/blocks/event-info/index.js, when all event dates are in the past, the fallback logic intentionally takes the latest start date and latest end date independently (even from different events) to handle overlapping events correctly. This approach captures the full scope of recent event activity rather than constraining to a single event's date range.
Learnt from: gin0115
PR: a8cteam51/simple-events#21
File: src/event-functions.php:544-547
Timestamp: 2025-07-07T09:19:18.986Z
Learning: The `se_event_get_calendar_link` function in `src/event-functions.php` contains legacy code, which explains why it may have redundant or suboptimal implementation patterns.
src/event-functions.php (1)
Learnt from: gin0115
PR: #21
File: src/event-functions.php:544-547
Timestamp: 2025-07-07T09:19:18.986Z
Learning: The se_event_get_calendar_link function in src/event-functions.php contains legacy code, which explains why it may have redundant or suboptimal implementation patterns.
src/blocks/event-info/event-manager.js (1)
Learnt from: gin0115
PR: #17
File: src/blocks/event-info/index.js:82-98
Timestamp: 2025-06-17T12:10:45.329Z
Learning: In src/blocks/event-info/index.js, when all event dates are in the past, the fallback logic intentionally takes the latest start date and latest end date independently (even from different events) to handle overlapping events correctly. This approach captures the full scope of recent event activity rather than constraining to a single event's date range.
src/blocks/event-info/index.js (1)
Learnt from: gin0115
PR: #17
File: src/blocks/event-info/index.js:82-98
Timestamp: 2025-06-17T12:10:45.329Z
Learning: In src/blocks/event-info/index.js, when all event dates are in the past, the fallback logic intentionally takes the latest start date and latest end date independently (even from different events) to handle overlapping events correctly. This approach captures the full scope of recent event activity rather than constraining to a single event's date range.
🪛 Biome (1.9.4)
src/blocks/event-info/index.js
[error] 341-341: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: gin0115
PR: a8cteam51/simple-events#17
File: src/blocks/event-info/index.js:82-98
Timestamp: 2025-06-17T12:10:45.329Z
Learning: In src/blocks/event-info/index.js, when all event dates are in the past, the fallback logic intentionally takes the latest start date and latest end date independently (even from different events) to handle overlapping events correctly. This approach captures the full scope of recent event activity rather than constraining to a single event's date range.
Learnt from: gin0115
PR: a8cteam51/simple-events#21
File: src/event-functions.php:544-547
Timestamp: 2025-07-07T09:19:18.986Z
Learning: The `se_event_get_calendar_link` function in `src/event-functions.php` contains legacy code, which explains why it may have redundant or suboptimal implementation patterns.
src/event-functions.php (1)
Learnt from: gin0115
PR: #21
File: src/event-functions.php:544-547
Timestamp: 2025-07-07T09:19:18.986Z
Learning: The se_event_get_calendar_link function in src/event-functions.php contains legacy code, which explains why it may have redundant or suboptimal implementation patterns.
src/blocks/event-info/event-manager.js (1)
Learnt from: gin0115
PR: #17
File: src/blocks/event-info/index.js:82-98
Timestamp: 2025-06-17T12:10:45.329Z
Learning: In src/blocks/event-info/index.js, when all event dates are in the past, the fallback logic intentionally takes the latest start date and latest end date independently (even from different events) to handle overlapping events correctly. This approach captures the full scope of recent event activity rather than constraining to a single event's date range.
src/blocks/event-info/index.js (1)
Learnt from: gin0115
PR: #17
File: src/blocks/event-info/index.js:82-98
Timestamp: 2025-06-17T12:10:45.329Z
Learning: In src/blocks/event-info/index.js, when all event dates are in the past, the fallback logic intentionally takes the latest start date and latest end date independently (even from different events) to handle overlapping events correctly. This approach captures the full scope of recent event activity rather than constraining to a single event's date range.
🪛 Biome (1.9.4)
src/blocks/event-info/index.js
[error] 341-341: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (3)
src/event-functions.php (1)
781-790: Good improvement to timezone handling robustnessThese changes properly handle
DateTimeZoneinstances and validate the timezone parameter, preventing potential type errors and ensuring consistent behavior when the site timezone fallback is used.src/blocks/event-info/event-manager.js (1)
30-40: Improved hash generation for better date trackingThe updated
createDateHashfunction now generates more stable and unique hashes by incorporating the post ID instead of timestamps. This ensures consistent hash values across different operations while maintaining uniqueness through the random string suffix.src/blocks/event-info/index.js (1)
660-686: Clean refactoring of the renderPreview functionThe explicit function body and organized attributes object improve code readability and maintainability without changing functionality.
…as the typehint lays out. Also handle racecondition when syncing dates and update post run in wrong order
Changes proposed in this Pull Request
This pull request introduces several enhancements and bug fixes to the event management system, focusing on improving date handling, synchronization, and block rendering. The most critical changes involve updates to the
createDateHashfunction, adjustments to date synchronization logic, and refinements to the block preview rendering process.Enhancements to Date Handling:
createDateHashfunction: Updated the function to include apostIdparameter for generating hashes. IfpostIdis not provided, it defaults to the current post ID combined with a random alphanumeric string for uniqueness.dateManager: Added logic to ensure the hash is correctly generated for each date during initialization.Synchronization Improvements:
UnsavedChangesWarningcomponent to improve readability and reliability when detecting unsaved changes.Block Rendering Refinements:
renderPreviewfunction to encapsulate block attributes in a single object, simplifying the ServerSideRender logic and improving maintainability. [1] [2]Miscellaneous Fixes:
se_create_date_time_from_timestampto ensure proper handling ofDateTimeZoneinstances and fallback to the site timezone when necessary.Testing instructions
Mentions #
Summary by CodeRabbit
Bug Fixes
Refactor