Skip to content

fix: skip activity-stream assets on non-network admin dashboard#785

Merged
superdav42 merged 1 commit intomainfrom
feature/fix-activity-stream-network-only
Apr 10, 2026
Merged

fix: skip activity-stream assets on non-network admin dashboard#785
superdav42 merged 1 commit intomainfrom
feature/fix-activity-stream-network-only

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Apr 10, 2026

Summary

  • The enqueue_scripts() method in Dashboard_Widgets only checked $pagenow === 'index.php', which matches both the per-site dashboard (/wp-admin/index.php) and the network dashboard (/wp-admin/network/index.php).
  • The activity-stream Vue app (#activity-stream-content) is only rendered on the network dashboard via wp_network_dashboard_setup. Loading the script on the per-site dashboard caused a JS console error: [Vue warn]: Cannot find element: #activity-stream-content.
  • Fix: add is_network_admin() guard in enqueue_scripts() to bail early when not on the network admin.

Files Changed

  • inc/class-dashboard-widgets.php — added is_network_admin() early-return guard

Testing

  • Visit /wp-admin/index.php (per-site dashboard): no Vue console error, activity-stream script not loaded.
  • Visit /wp-admin/network/index.php (network dashboard): activity-stream widget loads and functions correctly.

Runtime Testing

Risk level: Low — guard condition only, no logic change to the widget itself.
Verification: self-assessed — the fix is a single conditional that prevents script enqueue on the wrong screen.

Summary by CodeRabbit

  • Bug Fixes
    • Optimized dashboard widget asset loading to prevent unnecessary resources from being loaded on per-site admin dashboards, ensuring activity-stream widget resources display only in appropriate contexts.

The enqueue_scripts() method only checked $pagenow === 'index.php',
which matches both /wp-admin/index.php (per-site dashboard) and
/wp-admin/network/index.php (network dashboard). The activity-stream
Vue app and its #activity-stream-content mount point are only rendered
on the network dashboard via wp_network_dashboard_setup, so loading
the script on the per-site dashboard caused:

  [Vue warn]: Cannot find element: #activity-stream-content

Add an is_network_admin() guard to bail early on the per-site dashboard.
@superdav42 superdav42 added the bug Something isn't working label Apr 10, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd4dfbce-8955-4b21-975b-2f909146f118

📥 Commits

Reviewing files that changed from the base of the PR and between 6b105db and 7f710b0.

📒 Files selected for processing (1)
  • inc/class-dashboard-widgets.php

📝 Walkthrough

Walkthrough

The PR modifies Dashboard_Widgets::enqueue_scripts() to add a conditional early return that prevents enqueueing activity-stream widget assets and inline nonce on per-site dashboards. Assets are now loaded only in network admin context.

Changes

Cohort / File(s) Summary
Activity-Stream Widget Asset Enqueuing
inc/class-dashboard-widgets.php
Added early return guard in enqueue_scripts() to conditionally skip asset enqueuing when not in network admin context (! is_network_admin()), restricting activity-stream widget dependencies to network dashboard only.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 A guardian clause hops into place,
Network dashboards now set the pace,
Per-site views skip the extra load,
Assets travel the right road! 🛤️

🚥 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 'fix: skip activity-stream assets on non-network admin dashboard' directly and specifically describes the main change: adding a guard to prevent activity-stream assets from loading on non-network admin contexts.
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 feature/fix-activity-stream-network-only

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.

@superdav42 superdav42 merged commit 2060784 into main Apr 10, 2026
11 checks passed
@superdav42
Copy link
Copy Markdown
Collaborator Author

Summary

  • The enqueue_scripts() method in Dashboard_Widgets only checked $pagenow === 'index.php', which matches both the per-site dashboard (/wp-admin/index.php) and the network dashboard (/wp-admin/network/index.php).
  • The activity-stream Vue app (#activity-stream-content) is only rendered on the network dashboard via wp_network_dashboard_setup. Loading the script on the per-site dashboard caused a JS console error: [Vue warn]: Cannot find element: #activity-stream-content.
  • Fix: add is_network_admin() guard in enqueue_scripts() to bail early when not on the network admin.

Files Changed

  • inc/class-dashboard-widgets.php — added is_network_admin() early-return guard

Testing

  • Visit /wp-admin/index.php (per-site dashboard): no Vue console error, activity-stream script not loaded.
  • Visit /wp-admin/network/index.php (network dashboard): activity-stream widget loads and functions correctly.

Runtime Testing

Risk level: Low — guard condition only, no logic change to the widget itself.
Verification: self-assessed — the fix is a single conditional that prevents script enqueue on the wrong screen.


Merged via PR #785 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).


aidevops.sh v3.6.235 spent 6m on this as a headless bash routine.

@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 2aaea46 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 40 (-1 / -3% ) 37.75 MB 816.00 ms 172.00 ms (-20.00 ms / -12% ) 1040.50 ms 1964.00 ms 1874.95 ms 92.30 ms (+5.35 ms / +6% )
1 56 49.02 MB 927.00 ms (+39.50 ms / +4% ) 148.50 ms (+3.50 ms / +2% ) 1077.50 ms (+46.00 ms / +4% ) 2052.00 ms (+58.00 ms / +3% ) 1972.30 ms (+59.10 ms / +3% ) 81.40 ms

superdav42 added a commit that referenced this pull request Apr 12, 2026
…gets_Test

Add 7 unit tests covering the template_selection → template_id validation
mapping fix from PR #800:
- template_selection required attribute maps to template_id rule key
- min:1 guard rejects template_id=0 during checkout
- positive template_id passes validation
- no min:1 added when template_selection field is absent
- template_id=0 allowed with base rule (admin/network context)
- non-template required fields still map to themselves

Fix Dashboard_Widgets_Test failure caused by PR #785 adding
is_network_admin() guard to enqueue_scripts(). The test now uses
set_current_screen('dashboard-network') to simulate the network admin
context. Also adds a new test confirming the per-site dashboard does
NOT enqueue wu-activity-stream.
superdav42 added a commit that referenced this pull request Apr 12, 2026
…gets_Test (#801)

Add 7 unit tests covering the template_selection → template_id validation
mapping fix from PR #800:
- template_selection required attribute maps to template_id rule key
- min:1 guard rejects template_id=0 during checkout
- positive template_id passes validation
- no min:1 added when template_selection field is absent
- template_id=0 allowed with base rule (admin/network context)
- non-template required fields still map to themselves

Fix Dashboard_Widgets_Test failure caused by PR #785 adding
is_network_admin() guard to enqueue_scripts(). The test now uses
set_current_screen('dashboard-network') to simulate the network admin
context. Also adds a new test confirming the per-site dashboard does
NOT enqueue wu-activity-stream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant