Skip to content

Fix React render-phase update warning in Course Settings sidebar - #8041

Merged
donnapep merged 2 commits into
trunkfrom
fix/course-settings-render-phase-dispatch
Jun 29, 2026
Merged

donnapep merged 2 commits into
trunkfrom
fix/course-settings-render-phase-dispatch

Conversation

@donnapep

@donnapep donnapep commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Problem

Opening Course Settings in the course editor logs a React dev-mode warning:

Warning: Cannot update a component (`ComplementaryAreaToggle`) while
rendering a different component (`w`).

SenseiSettingsDocumentSidebar dispatched openGeneralSidebar and toggleEditorPanelOpened directly in its render body. Triggering store updates during render is a render-phase update, which React warns about (and can cause double-renders / stale state).

The bad pattern has existed since 2022; it only surfaced as a visible warning once WordPress core bundled React 18 (WP 6.2+) and the dev React build was loaded (SCRIPT_DEBUG).

Fix

Wrap the dispatch side-effects in useEffect, keyed on isSenseiEditorPanelOpen, so they run after commit instead of during render. Behavior is unchanged — clicking "Course Settings" still opens the plugin sidebar and closes the document panel.

Also

Document the existing PR-milestone CI requirement in AGENTS.md (it was previously only in .github/), including the REST-API fallback for assigning milestones.

Test plan

  1. Course editor with SCRIPT_DEBUG on, dev React loaded.
  2. Open the editor options menu → click Course Settings.
  3. Course Settings plugin sidebar opens.
  4. Browser console: no "Cannot update a component while rendering" warning.

🤖 Generated with Claude Code

SenseiSettingsDocumentSidebar dispatched openGeneralSidebar and
toggleEditorPanelOpened directly in its render body, triggering React's
"Cannot update a component while rendering a different component" warning
on ComplementaryAreaToggle. Wrap the dispatches in useEffect so they run
after commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 29, 2026 16:27
@donnapep donnapep self-assigned this Jun 29, 2026

Copilot AI 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.

Pull request overview

This PR fixes a React render-phase update warning triggered when opening the Sensei Course Settings sidebar in the WordPress course editor by moving store-dispatch side effects out of the render body and into a useEffect hook.

Changes:

  • Move openGeneralSidebar / toggleEditorPanelOpened dispatches into a useEffect keyed on isSenseiEditorPanelOpen to avoid render-phase updates.
  • Add a changelog entry documenting the fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
changelog/fix-course-settings-render-phase-dispatch Adds a patch-level “fixed” changelog entry for the React warning.
assets/js/admin/course-settings-plugin-sidebar.js Wraps sidebar/panel dispatch logic in useEffect to prevent render-phase updates under React 18 dev builds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@donnapep donnapep added this to the 4.26.2 milestone Jun 29, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

WordPress Playground Preview

The changes in this pull request can previewed and tested using a WordPress Playground instance.

Open WordPress Playground Preview

@donnapep
donnapep merged commit 9fb14d1 into trunk Jun 29, 2026
22 checks passed
@donnapep
donnapep deleted the fix/course-settings-render-phase-dispatch branch June 29, 2026 16:37
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.

2 participants