Skip to content

fix(angular/modal): Fix programmatic modal closing#2621

Merged
danielleroux merged 2 commits into
mainfrom
fix/IX-4365_close_modal_fix
Jun 30, 2026
Merged

fix(angular/modal): Fix programmatic modal closing#2621
danielleroux merged 2 commits into
mainfrom
fix/IX-4365_close_modal_fix

Conversation

@dmytro-halimov

@dmytro-halimov dmytro-halimov commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

GitHub Issue Number: #2595
JIRA Ref: #IX-4365

💡 What is the new behavior?

[Angular package]: Fixes modal closing race condition where close() or dismiss() called before modal element initialization would silently fail. Pending actions are now queued and executed once the modal element is set.

🏁 Checklist

A pull request can only be merged if all of these conditions are met (where applicable):

  • 🦮 Accessibility (a11y) features were implemented
  • 🗺️ Internationalization (i18n) - no hard coded strings
  • 📲 Responsiveness - components handle viewport changes and content overflow gracefully
  • 📕 Add or update a Storybook story
  • 📄 Documentation was reviewed/updated siemens/ix-docs
  • 🧪 Unit tests were added/updated and pass (pnpm test)
  • 📸 Visual regression tests were added/updated and pass (Guide)
  • 🧐 Static code analysis passes (pnpm lint)
  • 🏗️ Successful compilation (pnpm build, changes pushed)

👨‍💻 Help & support

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a race condition where modal close()/dismiss() could be missed if called before the modal was fully initialized.
    • Modal actions are now queued and automatically executed once the modal becomes ready.
    • If both close and dismiss are requested early, only the first pending action is applied to keep behavior consistent.
  • Tests
    • Expanded modal service coverage to validate immediate vs deferred close/dismiss behavior and the “first action wins” scenario.

@netlify

netlify Bot commented Jun 23, 2026

Copy link
Copy Markdown

Deploy Preview for ix-storybook canceled.

Name Link
🔨 Latest commit afd94e0
🔍 Latest deploy log https://app.netlify.com/projects/ix-storybook/deploys/6a3bd5ee8d405d00091865ca

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

IxActiveModal now queues close() and dismiss() calls made before modalElement is available, then flushes the queued action when setModalElement() runs. Tests cover immediate and deferred dispatch paths, and the changeset records the patch release.

Changes

Pending Modal Action Queue

Layer / File(s) Summary
PendingModalAction type and queued dispatch
packages/angular/common/src/providers/modal/modal-ref.ts
Defines PendingModalAction<TReason> and pendingAction, queues close()/dismiss() when modalElement is missing, and flushes the stored action in setModalElement().
Modal service coverage
packages/angular/common/src/providers/modal/modal.service.spec.ts
Adds mock clearing setup and tests for immediate dispatch, deferred dispatch after setModalElement(), and first-pending-action wins behavior.
Changeset entry
.changeset/fix-modal-closing-race.md
Adds the patch release note for the modal closing race-condition fix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped by the modal, then paused in the dew,
Queued up a close call till the element came through.
Dismiss waited patiently, tucked safe in the night,
Then setModalElement said, “Go on—take flight!”

🚥 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 matches the main change: fixing programmatic modal closing in the Angular modal implementation.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 fix/IX-4365_close_modal_fix

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.

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: afd94e0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@siemens/ix-angular Patch
@siemens/ix-docs Patch
@siemens/ix Patch
@siemens/ix-react Patch
@siemens/ix-vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a mechanism to queue modal actions ('close' or 'dismiss') when the underlying modal element is not yet initialized, preventing errors during programmatic modal closing. It also adds comprehensive unit tests to verify this behavior. The review feedback suggests adding a changeset file for this consumer-relevant bug fix as required by the style guide, and recommends refactoring the conditional logic in 'setModalElement' to use an 'else if' block instead of an early return.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/angular/common/src/providers/modal/modal-ref.ts
Comment thread packages/angular/common/src/providers/modal/modal-ref.ts
@danielleroux

Copy link
Copy Markdown
Collaborator

@dmytro-halimov Just an idea my side would it make sense to have some QoL feature like a data-ix-modal-close and a data-ix-modal-dismiss which can be placed of an any element inside the ix-modal this will then perform the method call?

@dmytro-halimov dmytro-halimov marked this pull request as ready for review June 24, 2026 07:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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)
packages/angular/common/src/providers/modal/modal-ref.ts (1)

37-61: 📐 Maintainability & Code Quality | 🟡 Minor

Add an @siemens/ix-angular changeset for this modal behavior change.
close/dismiss now defer until modalElement exists, so this is consumer-visible and needs a changeset unless it is strictly internal-only. Include Fixes #2595`` in the summary if this release should close the issue.

🤖 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 `@packages/angular/common/src/providers/modal/modal-ref.ts` around lines 37 -
61, The deferred close/dismiss behavior in modal-ref is consumer-visible, so add
a changeset for this change in `@siemens/ix-angular`. Update the release note
summary to describe that ModalRef.close and ModalRef.dismiss now queue a
pendingAction until modalElement exists, and include Fixes `#2595` in the summary
if this release should close the issue. Use the ModalRef class and its
close/dismiss behavior as the reference point when creating the changeset.

Source: Path instructions

🤖 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 `@packages/angular/common/src/providers/modal/modal-ref.ts`:
- Around line 37-61: The deferred close/dismiss behavior in modal-ref is
consumer-visible, so add a changeset for this change in `@siemens/ix-angular`.
Update the release note summary to describe that ModalRef.close and
ModalRef.dismiss now queue a pendingAction until modalElement exists, and
include Fixes `#2595` in the summary if this release should close the issue. Use
the ModalRef class and its close/dismiss behavior as the reference point when
creating the changeset.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2950e442-5c80-4a2e-963c-fe3d39ee0b78

📥 Commits

Reviewing files that changed from the base of the PR and between 617d8a6 and 03b9945.

📒 Files selected for processing (2)
  • packages/angular/common/src/providers/modal/modal-ref.ts
  • packages/angular/common/src/providers/modal/modal.service.spec.ts

@danielleroux danielleroux left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Changeset missing
  • PR Title is misleading change is not core related only angular related
  • Adapt description to make clear that only the angular service is affected

@nuke-ellington nuke-ellington added this to the 5.1.0 milestone Jun 24, 2026
@dmytro-halimov dmytro-halimov changed the title fix(core/modal): Fix programmatic modal closing fix(angular/modal): Fix programmatic modal closing Jun 24, 2026
@dmytro-halimov

Copy link
Copy Markdown
Collaborator Author

@dmytro-halimov Just an idea my side would it make sense to have some QoL feature like a data-ix-modal-close and a data-ix-modal-dismiss which can be placed of an any element inside the ix-modal this will then perform the method call?

yeah I think this would make sense for core package. But if I get it correctly, these data attributes would only handle user clicks after initial render happens, so it wouldn't cover these programmatic race conditions, the queue in Angular package is still needed.
I can maybe create a ticket for it or do you prefer to do it in this scope?

@danielleroux danielleroux merged commit e80978e into main Jun 30, 2026
16 checks passed
@danielleroux danielleroux deleted the fix/IX-4365_close_modal_fix branch June 30, 2026 06:43
@sonarqubecloud

Copy link
Copy Markdown

@github-actions github-actions Bot mentioned this pull request Jun 30, 2026
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.

3 participants