Skip to content

fix(angular): set tabs outlet before emitting ionTabsWillChange - #31814

Open
gaurav0107 wants to merge 1 commit into
ionic-team:mainfrom
gaurav0107:fix/31674-iontabs-outlet-is-undefined-when-the-fir
Open

gaurav0107 wants to merge 1 commit into
ionic-team:mainfrom
gaurav0107:fix/31674-iontabs-outlet-is-undefined-when-the-fir

Conversation

@gaurav0107

Copy link
Copy Markdown

Issue number: resolves #31674


What is the current behavior?

When ion-tabs renders after the router has already activated the tab route (for example ion-tabs behind an @if, or a tabs page rendered by Angular's <router-outlet>), the inner ion-router-outlet activates the first tab while IonTabs is still in its first change detection. ionTabsWillChange then fires before the non-static @ViewChild('outlet') query has resolved, so IonTabs.outlet is undefined in that first handler. Anything that reads outlet, or calls getSelected(), throws TypeError: Cannot read properties of undefined.

What is the new behavior?

  • The ion-router-outlet binding in the IonTabs template now passes its #outlet template reference into onStackWillChange, which sets outlet before emitting ionTabsWillChange. This is the approach suggested in the issue.
  • The standalone and lazy IonTabs share the same template, so both are updated.
  • Added a standalone test page (/standalone/tabs-outlet-ready) that renders ion-tabs behind an @if that becomes true after the tab route has activated, plus an e2e test checking that outlet is defined on the first ionTabsWillChange.

Does this introduce a breaking change?

  • Yes
  • No

Other information

  • The new e2e test fails without the fix (outlet is undefined on the first event) and passes with it.
  • Ran locally against the ng22 test app: all tabs specs (standalone and lazy) and the full Angular e2e suite (236 passed). npm run lint, npm run build and npm run test in packages/angular pass.
  • onStackWillChange is @internal, and the new parameter is optional.

🤖 Opened with Superhuman, an open-source contribution agent.

When ion-tabs renders after the router has already activated the tab
route, the inner ion-router-outlet activates the first tab while IonTabs
is still in its first change detection. ionTabsWillChange then fires
before the non-static `outlet` view query resolves, so handlers that read
`outlet` (or call `getSelected()`) throw.

Pass the `#outlet` template reference into `onStackWillChange` from both
the standalone and lazy IonTabs templates and assign `outlet` before
emitting.

resolves ionic-team#31674
@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

@gaurav0107 is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the package: angular @ionic/angular package label Nov 24, 2026
@gaurav0107
gaurav0107 marked this pull request as ready for review November 24, 2026 00:32
@gaurav0107
gaurav0107 requested a review from a team as a code owner November 24, 2026 00:32
@gaurav0107
gaurav0107 requested a review from thetaPC November 24, 2026 00:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: IonTabs.outlet is undefined when the first ionTabsWillChange fires (standalone Angular)

1 participant