Skip to content

fix(dashboard): resolve wu_moment ReferenceError on network dashboard activity stream#705

Merged
superdav42 merged 1 commit into
mainfrom
bugfix/fix-activity-stream-wu-moment
Mar 30, 2026
Merged

fix(dashboard): resolve wu_moment ReferenceError on network dashboard activity stream#705
superdav42 merged 1 commit into
mainfrom
bugfix/fix-activity-stream-wu-moment

Conversation

@superdav42

@superdav42 superdav42 commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Move wu-activity-stream script enqueue from the view template (activity-stream.php) to Dashboard_Widgets::enqueue_scripts() so it runs during admin_enqueue_scripts where WordPress properly resolves the dependency chain
  • Add moment as a declared dependency of wu-functions since functions.js uses moment.tz/moment.utc in wu_moment()
  • Add unit test verifying wu-activity-stream is enqueued with correct dependencies on index.php

Problem

The Activity Stream widget on the network admin dashboard was permanently stuck on "Loading..." with:

Uncaught ReferenceError: wu_moment is not defined
    at HTMLDocument.<anonymous> (activity-stream.js:4:10)

activity-stream.js was enqueued inside the view template during widget rendering (meta_box output phase), which fires after admin_enqueue_scripts. WordPress cannot properly resolve the dependency chain for scripts enqueued that late, so wu-functions (which defines window.wu_moment) was not guaranteed to load before activity-stream.js executed.

Fix

Moved the wp_enqueue_script('wu-activity-stream', ...) call from views/dashboard-widgets/activity-stream.php into Dashboard_Widgets::enqueue_scripts(), which hooks on admin_enqueue_scripts. This ensures WordPress resolves the full dependency chain (moment -> wu-functions -> wu-activity-stream) before any script executes.

Also added moment as an explicit dependency of wu-functions since functions.js line 626-634 defines wu_moment() which calls moment.tz() / moment.utc().

Verification

  • Browser-tested on the network dashboard: Activity Stream widget now loads and displays events correctly
  • wu_moment is not defined error is gone
  • All 12 Dashboard_Widgets_Test tests pass (including new test)
  • PHPStan clean

aidevops.sh v3.5.463 plugin for OpenCode v1.3.4 with claude-opus-4-6 spent 39m and 15,589 tokens on this as a headless worker.

Summary by CodeRabbit

  • Refactor

    • Reorganized activity stream script loading to resolve dependencies and timing issues during dashboard initialization.
  • Tests

    • Added test coverage for activity stream script enqueuing on the dashboard index page.

…cripts

The activity-stream.js was enqueued inside the view template during widget
rendering (meta_box output), which fires after admin_enqueue_scripts. WordPress
cannot properly resolve the dependency chain for scripts enqueued that late,
so wu-functions (which defines window.wu_moment) was not loaded before
activity-stream.js executed, causing 'ReferenceError: wu_moment is not defined'
and leaving the Activity Stream widget stuck on 'Loading...' permanently.

Move the wp_enqueue_script call to Dashboard_Widgets::enqueue_scripts() where
it runs during admin_enqueue_scripts, and add moment as a declared dependency
of wu-functions since functions.js uses moment.tz/moment.utc in wu_moment.
@coderabbitai

coderabbitai Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 911d28f0-8eae-4ee0-8e36-ff856ec111b6

📥 Commits

Reviewing files that changed from the base of the PR and between f470a73 and c4020d7.

📒 Files selected for processing (4)
  • inc/class-dashboard-widgets.php
  • inc/class-scripts.php
  • tests/WP_Ultimo/Dashboard_Widgets_Test.php
  • views/dashboard-widgets/activity-stream.php

📝 Walkthrough

Walkthrough

This change centralizes the enqueuing of the wu-activity-stream script from the dashboard widgets view template to the dashboard widgets class, ensuring proper dependency resolution, explicit nonce injection, and standardized script loading through WordPress's admin_enqueue_scripts hook.

Changes

Cohort / File(s) Summary
Script Enqueuing Centralization
inc/class-dashboard-widgets.php
Added centralized enqueuing of wu-activity-stream script within enqueue_scripts() with explicit dependencies on wu-vue, wu-functions, and moment, plus inline script injection to define wu_activity_stream_nonce before script execution.
Dependency Management
inc/class-scripts.php
Updated wu-functions script dependencies to include moment, ensuring proper script load ordering.
View Template
views/dashboard-widgets/activity-stream.php
Removed in-template script registration and enqueuing; replaced with comment indicating script is handled by centralized Dashboard_Widgets::enqueue_scripts().
Testing
tests/WP_Ultimo/Dashboard_Widgets_Test.php
Added new test test_enqueue_scripts_enqueues_activity_stream_on_index() verifying activity-stream script enqueues with correct dependencies (wu-functions, moment).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • PR #510: Directly addresses the same dashboard widget script loading improvements and wu-functions dependency chain, ensuring scripts load in correct order.

Poem

🐰 Scripts once scattered, now unite with care,
Dependencies dance in the enqueue layer,
From view to class, a hop toward the light,
WordPress hooks make everything right,
The nonce arrives before the deed is done—
Organized scripts make coding fun! 🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main fix: moving script enqueuing to resolve the wu_moment ReferenceError on the network dashboard activity stream.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/fix-activity-stream-wu-moment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions

Copy link
Copy Markdown

Performance Test Results

Performance test results for 1a9bdb9 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 39 (-2 / -4% ) 37.73 MB 952.00 ms (+77.50 ms / +8% ) 218.00 ms (+52.00 ms / +24% ) 1142.50 ms (+50.00 ms / +4% ) 2162.00 ms (+72.00 ms / +3% ) 2073.10 ms (+77.55 ms / +4% ) 96.55 ms (+4.10 ms / +4% )
1 56 49.01 MB 987.50 ms 157.00 ms 1147.50 ms 2182.00 ms 2102.70 ms 84.00 ms

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