Skip to content

Use Stimulus' own dispatch in form refreshes - #25363

Merged
myabc merged 1 commit into
devfrom
fix/refresh-on-form-changes-dispatch
Sep 16, 2026
Merged

myabc merged 1 commit into
devfrom
fix/refresh-on-form-changes-dispatch

Conversation

@myabc

@myabc myabc commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Ticket

No work package. Frontend test-output hygiene, following up on #24622.

What are you trying to accomplish?

Removes the refresh-on-form-changes `useDispatch()` is deprecated warning. It fired on every form refresh, so ten times in the controller's specs and in the browser console in development.

It also fixes a targeting bug. RefreshOnFormChangesController extended stimulus-use's ApplicationController, which replaces Stimulus' dispatch with the deprecated useDispatch() version. That version takes (eventName, detail), so this.dispatch('beforeSnapshot', { target: this.formTarget }) put target into the event detail and dispatched on the controller element instead of the form. The project creation wizard's submission form mounts the controller on a wrapper around its form, so the CKEditor listener on the form never saw the event.

What approach did you choose and why?

The controller now extends Stimulus' Controller directly and keeps useDebounce. It used nothing else from ApplicationController (isPreview, csrfToken, metaValue). Stimulus' built-in dispatch(name, { target }) already has the signature the call site was written for, and it produces the same refresh-on-form-changes:beforeSnapshot event name, bubbling by default, so the CKEditor listener is unaffected.

AI involvement

Collaborative – AI generated a substantial part of the code; I reviewed and understand every line.

Merge checklist

  • Added/updated tests — regression spec for a form target nested inside the controller element
  • Added/updated documentation in Lookbook (patterns, previews, etc) — n/a
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@myabc
myabc requested a lite review from Copilot September 15, 2026 18:01
@myabc myabc added javascript Pull requests that update Javascript code needs review labels Sep 15, 2026
@myabc
myabc marked this pull request as ready for review September 15, 2026 18:01
@github-actions

Copy link
Copy Markdown

Warning

This pull request does not link an OpenProject work package.

Please add a link to the work package in the description, or reference it in the
title in square brackets, e.g. [SLUG-123] My title here.

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.

🟡 Changes recommended

Add regression coverage for event targeting on nested form targets.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates the form-refresh controller to use Stimulus’s native dispatch API, removing the deprecated behavior while preserving debouncing.

Changes:

  • Replaces ApplicationController with Stimulus Controller.
  • Retains useDebounce.
  • Corrects event targeting for nested forms.

Review note: Add a regression test covering a wrapper controller with a nested form target.

File summaries
File Summary
frontend/src/stimulus/controllers/refresh-on-form-changes.controller.ts Uses native Stimulus dispatch and preserves debouncing.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/overviews/spec/features/managing_dashboard_page_spec.rb[1:1:1]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #25363, linked for reference only):

- `rspec ./modules/overviews/spec/features/managing_dashboard_page_spec.rb[1:1:1]`

Treat this as a standalone task, unrelated to PR #25363. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #25363 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @myabc to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @myabc, and request a review from @myabc.
On every commit, set @myabc as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@myabc myabc added the spec coverage Pull requests that primarily update specs – with few or no production changes label Sep 15, 2026
stimulus-use's `ApplicationController` swaps in its deprecated
`useDispatch()`, which warned on every refresh and read `{ target }` as
event detail instead of the element to dispatch on.
@myabc
myabc force-pushed the fix/refresh-on-form-changes-dispatch branch from 4770dfe to ad62cf3 Compare September 15, 2026 19:07
@myabc myabc removed the spec coverage Pull requests that primarily update specs – with few or no production changes label Sep 16, 2026
@myabc
myabc merged commit 947096e into dev Sep 16, 2026
18 of 19 checks passed
@myabc
myabc deleted the fix/refresh-on-form-changes-dispatch branch September 16, 2026 15:55
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

javascript Pull requests that update Javascript code needs review

Development

Successfully merging this pull request may close these issues.

3 participants