Skip to content

fix(core): avoid unhandled validation rejection when native input is missing EIX-154 - #2690

Open
alexkaduk wants to merge 5 commits into
mainfrom
feature/EIX-154-select
Open

fix(core): avoid unhandled validation rejection when native input is missing EIX-154#2690
alexkaduk wants to merge 5 commits into
mainfrom
feature/EIX-154-select

Conversation

@alexkaduk

@alexkaduk alexkaduk commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

💡 What is the current behavior?

HookValidationLifecycle schedules a fire-and-forget validation check with setTimeout in connectedCallback. That timer is not cleared on disconnect, and rejections from getNativeInputElement() are not caught.

For ix-select, getNativeInputElement() rejects with Error: Input element not found when the internal <input> is missing (early connect or teardown). That becomes an unhandled promise rejection — console noise in production and failed runs in environments that treat unhandled rejections as test failures (e.g. Vitest browser / Storybook interaction tests).

GitHub Issue Number: #2669
Jira: EIX-154

🆕 What is the new behavior?

Changes in packages/core/src/components/utils/input/validation.ts:

  • try/catch around getNativeInputElement() — missing native input skips aria wiring instead of rejecting
  • Persist the connect setTimeout id and clearTimeout on disconnect (and before scheduling again on reconnect)
  • .catch() on the scheduled validation promise
  • Return early when !host.isConnected after awaits so teardown does not write classes/ARIA on a detached host

Also:

🏁 Checklist

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

  • 🦮 Accessibility (a11y) features were implemented N/A — no a11y API/DOM contract change
  • 🗺️ Internationalization (i18n) - no hard coded strings N/A
  • 📲 Responsiveness - components handle viewport changes and content overflow gracefully N/A
  • 📕 Add or update a Storybook story N/A
  • 📄 Documentation was reviewed/updated siemens/ix-docs N/A
  • 🧪 Unit tests were added/updated and pass (pnpm test) Select CT added; core build + select unmount CT run locally
  • 📸 Visual regression tests were added/updated and pass (Guide) N/A — no visual/UI change
  • 🧐 Static code analysis passes (pnpm lint)
  • 🏗️ Successful compilation (pnpm build, changes pushed)

👨‍💻 Help & support

Summary by CodeRabbit

  • Bug Fixes
    • Fixed unhandled promise rejections when required form controls are removed or unmounted during validation.
    • Improved validation behavior when native inputs are unavailable, disconnected, or removed during setup and teardown.
    • Prevented stale validation and accessibility updates after controls are removed.
    • Cancelled pending validation checks during disconnection to keep form state consistent.

@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8ce699a

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 Patch
@siemens/ix-angular Patch
@siemens/ix-docs 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

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The validation lifecycle now identifies missing native inputs, cancels deferred checks, checks host connectivity during asynchronous operations, and prevents unhandled rejections during select unmount.

Changes

Validation lifecycle handling

Layer / File(s) Summary
Native input error contract
packages/core/src/components/utils/input/validation.ts, packages/core/src/components/select/select.tsx
The select component now rejects with NativeInputNotFoundError. Validation recognizes this error across bundles.
Host-scoped validation state
packages/core/src/components/utils/input/validation.ts
Validation tracks deferred checks, ignores expected missing-input failures, stops validity and ARIA updates after disconnection, and cancels pending work during cleanup.
Regression coverage and release note
packages/core/src/components/select/test/select.ct.ts, .changeset/select-validation-unmount-rejection.md
The select test covers required validation during asynchronous unmount. The changeset records the patch release entry.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • Issue 2669 — The validation changes and regression test address uncaught rejections caused by missing or unmounted native inputs.

Possibly related PRs

  • siemens/ix#2510 — The changes extend select validation behavior and add regression coverage.

Suggested reviewers: lzeiml, nuke-ellington

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: preventing unhandled validation rejections when the native input is missing.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/EIX-154-select

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.

@netlify

netlify Bot commented Aug 3, 2026

Copy link
Copy Markdown

Deploy Preview for ix-storybook ready!

Name Link
🔨 Latest commit 8ce699a
🔍 Latest deploy log https://app.netlify.com/projects/ix-storybook/deploys/6a797e0156d7aa0008e1ad1e
😎 Deploy Preview https://deploy-preview-2690--ix-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@alexkaduk
alexkaduk marked this pull request as ready for review August 4, 2026 20:30

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

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@packages/core/src/components/select/test/select.ct.ts`:
- Around line 1632-1657: Update the teardown validation test around the mocked
getNativeInputElement and valueChange dispatch so it triggers the actual
validator event/path used by select.tsx. Replace fixed 50 ms waits with a
deferred lookup promise and explicit synchronization for lookup completion and
teardown; if a valueChange handler exists, assert the mock lookup was invoked
before validating inputNotFoundErrors remains empty.

In `@packages/core/src/components/utils/input/validation.ts`:
- Around line 47-49: Update isValidationHostActive and the active-host guards at
the indicated validation-check points to accept the captured state and require
validationLifecycleState.get(host) === state, in addition to host.isConnected.
Pass each check’s own state object through every guard so resumed checks cannot
mutate the host after a reconnect creates a new lifecycle entry.
- Around line 281-286: The observer setup around componentWillLoad must also run
after reconnection, since disconnectedCallback clears
state.classMutationObserver. Move or reuse the existing class-observer creation
logic in the connectedCallback path of HookValidationLifecycle, guard it so
setup is idempotent, and add a regression test covering disconnect, reattach,
and subsequent class mutations.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 20ea8449-2d48-4d9e-92f5-c92a05a8657c

📥 Commits

Reviewing files that changed from the base of the PR and between 09fa2b6 and 9e385d3.

📒 Files selected for processing (3)
  • .changeset/select-validation-unmount-rejection.md
  • packages/core/src/components/select/test/select.ct.ts
  • packages/core/src/components/utils/input/validation.ts

Comment thread packages/core/src/components/select/test/select.ct.ts Outdated
Comment thread packages/core/src/components/utils/input/validation.ts Outdated
Comment thread packages/core/src/components/utils/input/validation.ts Outdated
@alexkaduk
alexkaduk force-pushed the feature/EIX-154-select branch from 50b0791 to 81e7e24 Compare August 5, 2026 07:18
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (1)
packages/core/src/components/utils/input/validation.ts (1)

116-128: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Store the initial-validation timer per host.

HookValidationLifecycle creates checkTimeoutId once for the decorated prototype. It is shared by all component instances. When a second instance connects, Lines 125-128 cancel the first instance's initial validation. When either instance disconnects, Lines 264-267 can cancel the other instance's validation.

This can leave required-state classes and ARIA attributes uninitialized. Store timeout state in a WeakMap keyed by host, and clear only that host's timer.

Also applies to: 235-240, 264-267

🤖 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/core/src/components/utils/input/validation.ts` around lines 116 -
128, Update HookValidationLifecycle so the initial-validation timeout is stored
per host in a WeakMap keyed by the component element, rather than in the shared
checkTimeoutId variable. In connectedCallback, the initial-validation scheduling
logic, and disconnectedCallback, read, clear, reset, and assign only the timer
associated with that host, preserving independent validation state across
component instances.
🤖 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.

Inline comments:
In `@packages/core/src/components/select/test/select.ct.ts`:
- Around line 1600-1603: Replace the plain Playwright test declaration for “does
not emit unhandled rejection when select is unmounted during validation” with
regressionTest, ensuring regressionTest is imported from `@utils/test` and the
existing test body remains unchanged.

In `@packages/core/src/components/utils/input/validation.ts`:
- Around line 144-149: Update the validation flow around getNativeInputElement
and the complete validation catch so only the known unavailable-input condition
is treated as validationElement undefined. Preserve that expected
connect/teardown behavior, but route all other failures—including errors from
shouldSuppressInternalValidation, hasValidValue, isTouched, validity retrieval,
and ARIA helpers—through the project’s established error-reporting path instead
of silently discarding them.

---

Outside diff comments:
In `@packages/core/src/components/utils/input/validation.ts`:
- Around line 116-128: Update HookValidationLifecycle so the initial-validation
timeout is stored per host in a WeakMap keyed by the component element, rather
than in the shared checkTimeoutId variable. In connectedCallback, the
initial-validation scheduling logic, and disconnectedCallback, read, clear,
reset, and assign only the timer associated with that host, preserving
independent validation state across component instances.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 33a603c2-094c-4147-965e-20d1b9ff10aa

📥 Commits

Reviewing files that changed from the base of the PR and between 09fa2b6 and 1546519.

📒 Files selected for processing (3)
  • .changeset/select-validation-unmount-rejection.md
  • packages/core/src/components/select/test/select.ct.ts
  • packages/core/src/components/utils/input/validation.ts

Comment thread packages/core/src/components/select/test/select.ct.ts
Comment thread packages/core/src/components/utils/input/validation.ts
@coderabbitai coderabbitai Bot mentioned this pull request Aug 5, 2026
9 tasks
@sonarqubecloud

Copy link
Copy Markdown

@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 (2)
packages/core/src/components/select/select.tsx (1)

1303-1307: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the public failure behavior.

getNativeInputElement() is exposed with @Method(). It now rejects when the native input is unavailable, but its JSDoc describes only successful resolution. Document this lifecycle failure behavior without making NativeInputNotFoundError an unintended public dependency.

As per coding guidelines, “Update component JSDoc, metadata inputs, Storybook stories, or test-app examples when public usage changes.”

🤖 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/core/src/components/select/select.tsx` around lines 1303 - 1307,
Update the JSDoc for the public getNativeInputElement() method to document that
its Promise rejects when the native input is unavailable during the component
lifecycle, describing the failure behavior without exposing
NativeInputNotFoundError as a required public dependency.

Source: Coding guidelines

packages/core/src/components/utils/input/validation.ts (1)

143-146: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Scope lifecycle state per host instance.

checkIfRequiredFunction, checkTimeoutId, and classMutationObserver are captured by the decorator closure. All instances of the decorated component share these variables. A second ix-select can clear the first timer or replace its callback. Disconnecting one instance can remove listeners or destroy the observer for another instance.

Store lifecycle state in a WeakMap keyed by the host, or on the instance. Add a two-instance connect/disconnect regression test.

Also applies to: 290-298

🤖 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/core/src/components/utils/input/validation.ts` around lines 143 -
146, Move checkIfRequiredFunction, checkTimeoutId, and classMutationObserver out
of the shared decorator closure and scope them per host instance using a WeakMap
keyed by the host (or equivalent instance state). Update the lifecycle logic
around the timeout cleanup and the related lines near 290-298 so each instance
only manages its own callback, timer, observer, and listeners. Add a regression
test that connects and disconnects two ix-select instances and verifies their
lifecycle state remains independent.
🤖 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/core/src/components/select/select.tsx`:
- Around line 1303-1307: Update the JSDoc for the public getNativeInputElement()
method to document that its Promise rejects when the native input is unavailable
during the component lifecycle, describing the failure behavior without exposing
NativeInputNotFoundError as a required public dependency.

In `@packages/core/src/components/utils/input/validation.ts`:
- Around line 143-146: Move checkIfRequiredFunction, checkTimeoutId, and
classMutationObserver out of the shared decorator closure and scope them per
host instance using a WeakMap keyed by the host (or equivalent instance state).
Update the lifecycle logic around the timeout cleanup and the related lines near
290-298 so each instance only manages its own callback, timer, observer, and
listeners. Add a regression test that connects and disconnects two ix-select
instances and verifies their lifecycle state remains independent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b7a0aea8-6052-4e7d-b0a4-ed89de9b060c

📥 Commits

Reviewing files that changed from the base of the PR and between 1546519 and 8ce699a.

📒 Files selected for processing (2)
  • packages/core/src/components/select/select.tsx
  • packages/core/src/components/utils/input/validation.ts

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