Skip to content

fix(dashboard): stop building vendor dashboard layout config on background requests - #3336

Open
akzmoudud wants to merge 1 commit into
developfrom
fix/vendor-dashboard-assets-on-background-requests
Open

fix(dashboard): stop building vendor dashboard layout config on background requests#3336
akzmoudud wants to merge 1 commit into
developfrom
fix/vendor-dashboard-assets-on-background-requests

Conversation

@akzmoudud

@akzmoudud akzmoudud commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)

Closes: https://github.com/getdokan/dokan-pro/issues/5580

Changes proposed in this Pull Request:

FullWidthVendorLayout::register_vendor_dashboard_assets() was hooked to init, which runs on every request — WP-Cron, Action Scheduler pings (every ~30s on any WooCommerce site), admin-ajax, REST and admin screens. On each of those it built the entire vendor dashboard layout config: vendor lookup, header nav, and a full dokan_get_dashboard_nav() pass (~50 navigation URL builds), then attached it as inline data to a script that is never enqueued outside the seller dashboard — so all of that work was discarded.

Measured on a plugin-heavy dev site: ~55 wasted dokan_get_navigation_url() calls per background request, ~150,000+ per day on an idle site. With WPML active each of those multiplies further (every URL translation re-enters the dashboard nav builder).

The fix (9-line diff):

  1. Hook the registration to wp_enqueue_scripts (priority 5, before the enqueue callback at 10) instead of init — it only fires on front-end page renders, so background requests never reach the code at all.
  2. Bail unless is_user_logged_in() && dokan_is_seller_dashboard() — the same condition the existing enqueue callback already uses. This check is unreliable on init (query not parsed yet) but valid on wp_enqueue_scripts, which is what makes the hook move necessary rather than just adding a guard.

Verified: zero calls from cron/AJAX/REST/admin/non-dashboard pages after the change; the dashboard page itself registers, localizes and enqueues exactly as before. Translated (WPML) dashboard pages keep working since dokan-wpml maps the page ID via the existing dokan_get_current_page_id filter.

Related Pull Request(s)

How to test the changes in this Pull Request:

  1. Enable the new vendor dashboard layout (dokan_appearance.vendor_layout_style = latest).
  2. Add error_log() inside dokan_get_navigation_url() (or use Query Monitor's hook panel) and hit wp-cron.php, admin-ajax.php or any /wp-json/ route: before this PR each hit logs dozens of navigation URL builds, after it logs none.
  3. Open the vendor dashboard as a vendor: the React app, sidebar nav and header must load exactly as before (vendorDashboardLayoutConfig present in page source).

Changelog entry

Stop building vendor dashboard assets and layout config on background requests

Previously the full-width vendor dashboard registered its assets and built its entire layout configuration on every request to the site, including WP-Cron, Action Scheduler, AJAX and REST API calls, where the result was always discarded. Now the work only happens on an actual logged-in seller dashboard page view, removing constant background overhead on every WooCommerce site running Dokan.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved vendor dashboard asset loading to run only on the seller dashboard.
    • Prevented unnecessary dashboard scripts, styles, and configuration from loading on other pages.
    • Updated asset loading behavior for the latest vendor layout to improve reliability.

…round requests

The full-width vendor dashboard registered its assets and built the whole
layout config (vendor lookup, header nav, full dashboard nav — ~50 URL
builds) on init, which runs for every request: cron, Action Scheduler
pings, admin-ajax, REST and admin screens included. The inline config
attached to a never-enqueued script was simply discarded on all of them.

Register on wp_enqueue_scripts instead — it only fires on front-end page
renders — and bail unless the request is a logged-in seller-dashboard
view, the only place the config is ever consumed. The seller-dashboard
check is valid here (unlike on init) because the query is parsed by the
time wp_enqueue_scripts runs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Vendor dashboard asset scoping

Layer / File(s) Summary
Scope dashboard asset registration
includes/Shortcodes/FullWidthVendorLayout.php
The latest vendor layout moves asset registration to wp_enqueue_scripts with priority 5 and skips registration unless the user is logged in and viewing the seller dashboard.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: mdasifhossainnadim

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: avoiding dashboard config work on background requests.
Description check ✅ Passed The description largely matches the template, covering changes, testing, related PRs, and changelog; only optional screenshot sections are missing.
✨ 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 fix/vendor-dashboard-assets-on-background-requests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
includes/Shortcodes/FullWidthVendorLayout.php (1)

196-197: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Prevent potential fatal error when $vendor is falsy.

The ternary operator on line 196 ($vendor ? ...) indicates that $vendor can evaluate to false or null. However, line 197 calls $vendor->get_avatar() unconditionally. If $vendor is indeed falsy, this will throw a fatal error.

Ensure safe property access by verifying $vendor before calling the method.

🐛 Proposed fix
-                                'name'   => $vendor ? $vendor->get_shop_name() : $user_name,
-                                'avatar' => $vendor->get_avatar() ?? VendorUtil::get_vendor_default_avatar_url(),
+                                'name'   => $vendor ? $vendor->get_shop_name() : $user_name,
+                                'avatar' => $vendor ? ( $vendor->get_avatar() ?? VendorUtil::get_vendor_default_avatar_url() ) : VendorUtil::get_vendor_default_avatar_url(),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@includes/Shortcodes/FullWidthVendorLayout.php` around lines 196 - 197, Update
the avatar assignment in the vendor data array to verify that $vendor is truthy
before calling get_avatar(). Preserve the existing
VendorUtil::get_vendor_default_avatar_url() fallback for missing vendors or
missing avatar values, while leaving the name handling unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@includes/Shortcodes/FullWidthVendorLayout.php`:
- Around line 196-197: Update the avatar assignment in the vendor data array to
verify that $vendor is truthy before calling get_avatar(). Preserve the existing
VendorUtil::get_vendor_default_avatar_url() fallback for missing vendors or
missing avatar values, while leaving the name handling unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8a8afdf2-7ce4-4660-a1a3-e830cb4efbb6

📥 Commits

Reviewing files that changed from the base of the PR and between cea9b11 and 16ab027.

📒 Files selected for processing (1)
  • includes/Shortcodes/FullWidthVendorLayout.php

@akzmoudud akzmoudud self-assigned this Jul 22, 2026
@akzmoudud akzmoudud added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Dev Review It requires a developer review and approval Needs: Testing This requires further testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant