Replies: 1 comment 1 reply
|
v22 has a brand new Toast component, v21 is only supported for security updates. Can you confirm if a similar issue happens in v22 Toast as well? |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
When multiple
p-toastmessages are open and their leave animations finish close together, Angular throws:TypeError: Cannot read properties of null (reading '_lView')This is reported via Sentry in production. The toast UI still appears, but the exception is thrown during close.
Environment
mastertoast source — same pattern still presentStack (relevant frames)
ToastItem.onAfterLeave → Toast.onMessageClose → messages.splice(event.index, 1) → this.cd.detectChanges() → NgForOf.ngDoCheck / _applyChanges → ViewContainerRef.get(...) → null → ViewContainerRef.move(null, ...) → insertImpl → viewRef._lView // crash
Full path goes through
@primeuix/motionleave callback →ToastItem.onAfterLeave→Toast.onMessageClose.Root cause (analysis)
In
toast.ts:*ngFor="let msg of messages; let i = index"(notrackBy/@fortrack).onMessageCloseremoves withmessages.splice(event.index, 1)using a numeric index from the child.this.cd.detectChanges()synchronously from the leave-animation callback.If two leave animations complete nearly at the same time, the second close can use a stale index. That desyncs the
messagesarray from theViewContainerRefviews.NgForOf._applyChangesthen doesmove(null)and Angular crashes onnull._lView.This is easier to hit when the same error toast is added twice quickly (e.g. double submit), then both auto-dismiss.
Expected behavior
Closing multiple toasts (including overlapping leave animations) should not throw.
Suggested fix
this.messages = this.messages?.filter(m => m !== event.message) ?? null@for (msg of messages; track msg)(or assign a stableidonadd()and track that).markForCheck()instead of forceddetectChanges()insideonAfterLeave/onMessageClose.All reactions