Skip to content

Conversation

@GaryJones
Copy link
Contributor

Summary

  • Fix calendar drag-and-drop silently failing to persist post date changes
  • Add defensive coding so AJAX requests proceed even if React store unavailable
  • Add regression tests for same-timestamp post retrieval

Problem

When dragging posts on the Edit Flow calendar, the JavaScript crashed with:

Cannot read properties of null (reading 'setCalendarIsLoading')

The root cause was that calendar.js used dispatch('edit-flow/calendar') but the React bundle that registers this data store wasn't listed as a dependency. The store was undefined when the jQuery code ran, causing the crash before the AJAX request was made.

Solution

  1. Script dependency fix (calendar.php): Reordered script enqueue so the React bundle loads before calendar.js, and added edit-flow-calendar-react-js as an explicit dependency.

  2. Defensive coding (calendar.js): Added getCalendarDispatch() helper that returns no-op functions if the store isn't available, ensuring the AJAX request always proceeds.

  3. Regression tests (CalendarModuleTest.php): Added tests verifying that posts with the same timestamp are correctly retrieved (the original reported symptom).

Test plan

  • Drag a post to a different day on the calendar
  • Verify the AJAX request is made (check Network tab)
  • Click "Reset" and verify the post stays on the new date
  • Drag multiple posts to the same day at the same time
  • Verify all posts appear after page refresh
  • Run composer test:integration -- --filter=CalendarModuleTest (24 tests pass)

Fixes #770

🤖 Generated with Claude Code

The calendar drag-and-drop was silently failing because the JavaScript
crashed before making the AJAX request. The error was:
"Cannot read properties of null (reading 'setCalendarIsLoading')"

Root cause: calendar.js used dispatch('edit-flow/calendar') but the
React bundle that registers this data store wasn't loaded as a
dependency, so the store was undefined when the jQuery code ran.

Changes:
- Reorder script enqueue so React bundle loads before calendar.js
- Add edit-flow-calendar-react-js as dependency of calendar.js
- Add getCalendarDispatch() helper with graceful fallback to no-op
  functions, ensuring AJAX requests proceed even if store unavailable
- Add regression tests for posts with same timestamp being retrieved

Fixes #770

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@GaryJones GaryJones requested a review from a team as a code owner December 21, 2025 17:14
@GaryJones GaryJones self-assigned this Dec 21, 2025
@GaryJones GaryJones added this to the Next (minor) milestone Dec 21, 2025
@GaryJones GaryJones merged commit 9296875 into develop Dec 21, 2025
12 checks passed
@GaryJones GaryJones deleted the fix/770-calendar-same-time-posts branch December 21, 2025 21:55
@GaryJones GaryJones mentioned this pull request Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Post on same hour disappear

2 participants