I'm submitting a ... (check one with "x")
[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Plunkr Case (Bug Reports)
Please demonstrate your case at stackblitz by using the issue template below. Issues without a test case have much less possibility to be reviewd in detail and assisted.
https://stackblitz.com/edit/angular-nnhvnm
Current behavior
When p-confirmDialog component is destroyed, code executed in confirmdialog's onDestroy throws exception:
AppComponent.html:3 ERROR Error: ViewDestroyedError: Attempt to use a destroyed view: detectChanges
at viewDestroyedError (errors.ts:52)
at Object.debugUpdateDirectives [as updateDirectives] (services.ts:382)
at checkAndUpdateView (view.ts:359)
at callWithDebugContext (services.ts:629)
at Object.debugCheckAndUpdateView [as checkAndUpdateView] (services.ts:346)
at ViewRef_.detectChanges (refs.ts:260)
at ConfirmDialog.disableModality (confirmdialog.ts:260)
at ConfirmDialog.onOverlayHide (confirmdialog.ts:344)
at ConfirmDialog.ngOnDestroy (confirmdialog.ts:351)
at callProviderLifecycles (provider.ts:570)
Expected behavior
ConfirmDialog is destroyed without exception.
Minimal reproduction of the problem with instructions
https://angular-nnhvnm.stackblitz.io click "Remove confirmation dialog from dom to trigger error" and see exception in console.
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
Angular version: 9.0.2
PrimeNG version: 9.0.0
Browser: Chrome 80
Language: TypeScript
Node (for AoT issues): v12.14.1
Thanks for the clear bug. After 2 days of head bashing I finally got here. We have the same exact issue.
in our case if we run one of these tests individually they work. But when the tests run and they both run we get that "ViewDestroyedError: Attempt to use a destroyed view: detectChanges" error
it('should create 071208071', async () => {
fixture.detectChanges();
expect(component).toBeDefined();
});
it('should create 071208071', async () => {
fixture.detectChanges();
expect(component).toBeDefined();
});
I our case I was able to work around this by mocking the function below.
_wSpyDisableModality = jest.spyOn(ConfirmDialog.prototype, 'disableModality').mockImplementation(() => {});
The real solution is the same thing that was done for this bug. Check to see if destroyed before doing change detection. #8044 and #8127
@ddehghan and @mfig, thanks for the pointing out of issue.
how to update my application with this ConfirmationDialog version ?
tnx advanced
Set for 9.0.1 tomorrow.
I'm having this same problem in 9.1.3
this.confirmationService.confirm({
message: "If there are unsaved changes, they will be lost. Do you want to continue?",
header: "Confirmation",
icon: "pi pi-exclamation-triangle",
accept: () => { this.router.navigate(["home"]); },
reject: () => { }
});
I am having this (same) issue with primeng 10.0.2.
Dirty tweaked with:
this.confirmationService.confirm({
message: "Are you sure you want to cancel?",
accept: () => setTimeout(() => this.navigateAway(), 200)
});
just to give it time to close properly.
Having this issue on v10 as well
Most helpful comment
I'm having this same problem in 9.1.3