Skip to content

[AGILE-301] Fix goal text being wiped on date selection in Sprint dialog#23851

Merged
myabc merged 3 commits into
release/17.6from
fix/AGILE-301-date-wipes-sprint-goal
Jun 24, 2026
Merged

[AGILE-301] Fix goal text being wiped on date selection in Sprint dialog#23851
myabc merged 3 commits into
release/17.6from
fix/AGILE-301-date-wipes-sprint-goal

Conversation

@myabc

@myabc myabc commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Ticket

https://community.openproject.org/wp/AGILE-301

What are you trying to accomplish?

Entering a start/finish date in the New sprint dialog triggered a form refresh (the duration preview) that wiped any goal text already typed. End users lost their sprint goal whenever they filled the dates after the goal.

Root cause: on refresh the form rebuilt the goal via find_or_initialize_by, which queried the database for an unsaved sprint (sprint_id IS NULL) and ignored the in-memory goal submitted with the request — rendering a blank field.

Note

This fixes a recently-introduced flake in modules/backlogs/spec/features/backlogs/create_spec.rb (e.g. "allows creating a new sprint with a sprint goal"), where the goal occasionally vanished before submission. The same out-of-order refresh races could surface intermittently across the backlogs create specs in CI.

What approach did you choose and why?

  • Sprint#goal_for now always reads the in-memory goals association, so a refresh re-renders the submitted goal instead of a blank one. This is the actual bug fix.
  • The Stimulus refresh-on-form-changes controller debounces the refresh and aborts any superseded request, so a slow earlier response can no longer land last and overwrite the form with stale state (the source of the residual flake).

Drive-by

Not related to the bug, but worth fixing while here: this PR includes a fix to make the controller safer to use with forms containing form inputs.

the controller's query serialization cast FormData to undefined to satisfy URLSearchParams. Replaced with a small serializeFormQuery helper that copies only string entries (so file inputs can't leak into the URL), drops the cast, and switches the reload to location.replace so a refresh no longer pushes a history entry.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

Reuses `Sprint#goal_for` when rebuilding the sprint form so a date
refresh no longer clears an unsaved goal. Covers the refresh path
that previously wiped the field.

https://community.openproject.org/wp/AGILE-301
@myabc myabc changed the title Fix/agile 301 date wipes sprint goal [AGILE-301[ Fix goal text being wiped on date selection in Sprint dialog Jun 22, 2026
@myabc myabc requested a review from Copilot June 22, 2026 20:47
@myabc myabc added needs review ruby Pull requests that update Ruby code javascript Pull requests that update Javascript code labels Jun 22, 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

Fixes a regression in the Backlogs sprint creation/edit dialog where changing the date range triggers a Turbo Stream form refresh that could discard the typed sprint goal (AGILE-301). The PR preserves the in-flight goal value across refreshes and reduces stale refresh overwrites client-side.

Changes:

  • Adjust sprint goal lookup/building to prefer the in-memory goal object during dialog refreshes.
  • Make Turbo Stream refresh requests debounced and abortable to prevent slower, stale responses from overwriting newer form state.
  • Add regression coverage (RSpec model + feature spec, plus a new Stimulus controller unit spec).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
modules/backlogs/spec/models/sprint_spec.rb Adds a spec ensuring goal_for can return an in-memory goal for unsaved sprints.
modules/backlogs/spec/features/backlogs/create_spec.rb Adds a regression feature spec and stabilizes date-change refresh timing around goal entry.
modules/backlogs/app/models/sprint.rb Changes goal_for implementation used to preserve goal state across refreshes.
modules/backlogs/app/components/backlogs/sprint_form_component.rb Uses goal_for / build instead of DB-backed find_or_initialize_by to keep the typed goal.
frontend/src/stimulus/controllers/refresh-on-form-changes.controller.ts Debounces refresh and aborts in-flight requests using @rails/request.js Turbo Stream handling.
frontend/src/stimulus/controllers/refresh-on-form-changes.controller.spec.ts Adds unit tests for query params, abort behavior, debouncing/coalescing, and error handling.

Comment thread modules/backlogs/app/models/sprint.rb
@myabc myabc force-pushed the fix/AGILE-301-date-wipes-sprint-goal branch from 80507c5 to 356ba4c Compare June 22, 2026 20:52
@myabc myabc changed the title [AGILE-301[ Fix goal text being wiped on date selection in Sprint dialog [AGILE-301] Fix goal text being wiped on date selection in Sprint dialog Jun 22, 2026
@myabc myabc marked this pull request as ready for review June 22, 2026 20:56
Debounces the Stimulus refresh and switches to `@rails/request.js`,
aborting superseded requests so a slow earlier response cannot land
last and overwrite the form with stale state.

https://community.openproject.org/wp/AGILE-301
@myabc myabc force-pushed the fix/AGILE-301-date-wipes-sprint-goal branch from 356ba4c to 04e21cb Compare June 22, 2026 21:03
Extract the query serialization into serializeFormQuery, which
copies only string entries so file inputs cannot leak into the URL
and the FormData cast to undefined is gone. Use location.replace so
a refresh does not push a history entry.
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/overviews/spec/features/project_description_widget_spec.rb[1:1: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 #23851, linked for reference only):

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

Treat this as a standalone task, unrelated to PR #23851. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #23851 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 flaky-spec Addresses a Flaky Spec label Jun 23, 2026

@ulferts ulferts 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.

Change looks good. I have questions but those do not prevent merging the PR.

@myabc myabc merged commit 96c7ef8 into release/17.6 Jun 24, 2026
20 checks passed
@myabc myabc deleted the fix/AGILE-301-date-wipes-sprint-goal branch June 24, 2026 09:50
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix ci flaky-spec Addresses a Flaky Spec javascript Pull requests that update Javascript code needs review ruby Pull requests that update Ruby code

Development

Successfully merging this pull request may close these issues.

3 participants