Skip to content

Fixed issue where sometimes a timezone object is passed not a string …#25

Merged
gin0115 merged 2 commits intoa8cteam51:trunkfrom
gin0115:fix/2_0_0__release-bugs
Jul 23, 2025
Merged

Fixed issue where sometimes a timezone object is passed not a string …#25
gin0115 merged 2 commits intoa8cteam51:trunkfrom
gin0115:fix/2_0_0__release-bugs

Conversation

@gin0115
Copy link
Collaborator

@gin0115 gin0115 commented Jul 22, 2025

…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 createDateHash function, adjustments to date synchronization logic, and refinements to the block preview rendering process.

Enhancements to Date Handling:

  • Improved createDateHash function: Updated the function to include a postId parameter for generating hashes. If postId is not provided, it defaults to the current post ID combined with a random alphanumeric string for uniqueness.
  • Date synchronization in dateManager: Added logic to ensure the hash is correctly generated for each date during initialization.

Synchronization Improvements:

  • Pre-save date synchronization: Modified the block's save logic to synchronize event dates before the post save begins. This ensures date updates are included in the save process and handles cases where date sync is still in progress.
  • Enhanced dirty state handling: Refactored the UnsavedChangesWarning component to improve readability and reliability when detecting unsaved changes.

Block Rendering Refinements:

  • Optimized preview rendering: Refactored the renderPreview function to encapsulate block attributes in a single object, simplifying the ServerSideRender logic and improving maintainability. [1] [2]

Miscellaneous Fixes:

  • Timezone handling in PHP utility function: Updated se_create_date_time_from_timestamp to ensure proper handling of DateTimeZone instances and fallback to the site timezone when necessary.
  • Error logging improvement: Enhanced error messages for better debugging, such as replacing plain text with emojis for visibility.

Testing instructions

Mentions #

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability and timing of event date saving during post save operations to ensure updated dates are consistently persisted.
    • Enhanced timezone handling for event date creation to better support different timezone formats.
  • Refactor

    • Optimized synchronization of event date attributes to reduce unnecessary updates and improve performance.
    • Improved code clarity in rendering previews and logging messages for easier maintenance.

gin0115 added 2 commits July 22, 2025 14:46
…as the typehint lays out. Also handle racecondition when syncing dates and update post run in wrong order
@coderabbitai
Copy link

coderabbitai bot commented Jul 22, 2025

Walkthrough

This set of changes updates three files related to event date management in a WordPress block. In event-manager.js, the createDateHash function now accepts an optional postId parameter, using it to generate unique hashes for event dates, and minor formatting adjustments are made elsewhere in the file. In index.js, the logic for saving event dates during post save operations is refactored to use a subscription to the WordPress data store, ensuring event dates are reliably synchronized with post saves. Additional optimizations include deep comparison for attribute synchronization and minor improvements to rendering and logging. In event-functions.php, the handling of the $timezone parameter in a date utility function is enhanced for better robustness.

Estimated code review effort

3 (~45 minutes)

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/blocks/event-info/index.js (2)

327-367: Excellent refactoring of the post save synchronization logic

The 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 synchronization

The deep comparison using JSON.stringify prevents unnecessary attribute updates and re-renders. Adding attributes.eventDates to the dependency array ensures proper reactivity.

Note: For large date arrays, consider using a more efficient deep comparison method like lodash's isEqual which is already imported in this file.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3640bc7 and 9d64863.

📒 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 robustness

These changes properly handle DateTimeZone instances 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 tracking

The updated createDateHash function 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 function

The explicit function body and organized attributes object improve code readability and maintainability without changing functionality.

@gin0115 gin0115 merged commit 0494a38 into a8cteam51:trunk Jul 23, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant