Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfirmDialog throws exception during onDestroy #8585

Closed
mfig opened this issue Feb 28, 2020 · 8 comments
Closed

ConfirmDialog throws exception during onDestroy #8585

mfig opened this issue Feb 28, 2020 · 8 comments
Assignees
Labels
LTS-FIXED-9.2.4 Fixed in PrimeNG LTS 9.2.4 LTS-FIXED-10.0.9 Fixed in PrimeNG LTS 10.0.9 Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@mfig
Copy link

mfig commented Feb 28, 2020

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

@ddehghan
Copy link

ddehghan commented Mar 2, 2020

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();
    });

@ddehghan
Copy link

ddehghan commented Mar 2, 2020

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

@yigitfindikli
Copy link
Contributor

@ddehghan and @mfig, thanks for the pointing out of issue.

@yigitfindikli yigitfindikli self-assigned this Mar 2, 2020
@yigitfindikli yigitfindikli added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Mar 2, 2020
@yigitfindikli yigitfindikli added this to the 9.0.1 milestone Mar 2, 2020
@lucksjb
Copy link

lucksjb commented Mar 12, 2020

how to update my application with this ConfirmationDialog version ?
tnx advanced

@cagataycivici
Copy link
Member

Set for 9.0.1 tomorrow.

@saunandrea
Copy link

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: () => { }
        });

@aemilianvs
Copy link

aemilianvs commented Dec 22, 2020

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.

@EuniceB
Copy link

EuniceB commented Jan 14, 2021

Having this issue on v10 as well

@yigitfindikli yigitfindikli modified the milestones: 9.0.1, 11.2.0 Jan 21, 2021
@yigitfindikli yigitfindikli reopened this Jan 21, 2021
@yigitfindikli yigitfindikli changed the title ConfirmDialog throws exception during onDestroy on v9.0.0 ConfirmDialog throws exception during onDestroy Jan 21, 2021
@yigitfindikli yigitfindikli added LTS-FIXED-10.0.9 Fixed in PrimeNG LTS 10.0.9 LTS-FIXED-9.2.4 Fixed in PrimeNG LTS 9.2.4 and removed LTS-PORTABLE labels Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTS-FIXED-9.2.4 Fixed in PrimeNG LTS 9.2.4 LTS-FIXED-10.0.9 Fixed in PrimeNG LTS 10.0.9 Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

8 participants