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

Modal may run openModal after component is already disconnected leaving state in the DOM #6594

Closed
jkieboom opened this issue Mar 14, 2023 · 11 comments
Assignees
Labels
4 - verified Issues that have been released and confirmed resolved. ArcGIS Maps SDK for JavaScript Issues logged by ArcGIS SDK for JavaScript team members. bug Bug reports for broken functionality. Issues should include a reproduction of the bug. estimate - 3 A day or two of work, likely requires updates to tests. impact - p3 - not time sensitive User set priority impact status of p3 - not time sensitive p - medium Issue is non core or affecting less that 60% of people using the library

Comments

@jkieboom
Copy link

Actual Behavior

Because calling openModal is async, it is possible for the component to become disconnected before openModal is actually run. In this case openModal will leave side effects in the DOM that are not cleaned up. In particular it leaves the overflow-hidden CSS class on the html node.

Expected Behavior

The modal component does not produce any side effects once disconnected.

Reproduction Sample

https://codepen.io/jkieboom/pen/NWLYgRe

Reproduction Steps

  1. Let codepen load
  2. Message in document should indicate that html element no longer has overflow-hidden CSS class (but does)
  3. Can also be inspected through devtools on the html element

Reproduction Version

@latest

Relevant Info

No response

Regression?

No response

Priority impact

p3 - not time sensitive

Impact

This was uncovered in our CI because it left state that affected other tests.

Esri team

ArcGIS Maps SDK for JavaScript

@jkieboom jkieboom added 0 - new New issues that need assignment. bug Bug reports for broken functionality. Issues should include a reproduction of the bug. needs triage Planning workflow - pending design/dev review. labels Mar 14, 2023
@github-actions github-actions bot added impact - p3 - not time sensitive User set priority impact status of p3 - not time sensitive ArcGIS Maps SDK for JavaScript Issues logged by ArcGIS SDK for JavaScript team members. labels Mar 14, 2023
@geospatialem geospatialem added p - medium Issue is non core or affecting less that 60% of people using the library estimate - 3 A day or two of work, likely requires updates to tests. labels Mar 30, 2023
@geospatialem geospatialem added this to the 2023 July Priorities milestone Mar 30, 2023
@geospatialem geospatialem removed the needs triage Planning workflow - pending design/dev review. label Mar 30, 2023
@driskull
Copy link
Member

Trying to get a fix for this but I'm seeing a bug with stencil. ionic-team/stencil#4070

If a component is removed right after its added it doesn't seem to call the disconnectedCallback. This is kind of a bad bug because it leaves listeners connected. cc @jcfranco

This fix can benefit from use of an AbortController to abort opening the modal after requestAnimationFrame if the controller was aborted in disconnectedCallback. But since the disconnectedCallback bug exists we can't really clean stuff up on disconnectedCallback.

I was thinking we should move the initial open logic into connectedCallback as well because it seems like openModal should be called if the component is moved in the DOM too, not just on first load.

@jcfranco
Copy link
Member

@driskull Thanks for digging. That bug is quite unfortunate. I'm afraid we can't do anything regarding that issue until it's fixed and we bump Stencil.

Regarding the issue at hand, I did notice that the repro case behaves differently depending on the output target used:

  • dist (lazy-loaded) - does not call the overridden componentDidLoad, but does remove the util class after the initial message is logged (see https://codepen.io/jcfranco/pen/JjeNpBL).
  • components – the overridden componentDidLoad is called, but throws errors due to it clobbering the original lifecycle method and the util class is also removed from the document after the initial message is logged (same as the codepen above).

@jkieboom Could you check if this is also happening in your testing environment? If not, would it be possible to get an updated repro case to better reflect the issue? LMK if we can help here.

I was thinking we should move the initial open logic into connectedCallback as well because it seems like openModal should be called if the component is moved in the DOM too, not just on first load.

IIRC, after initial load, openModal is then called by the open watcher, so this may not be necessary. I could be missing something, so please let me know if you're noticing inconsistent behavior here.

@jkieboom
Copy link
Author

jkieboom commented Jul 3, 2023

We don't actually override componentDidLoad in our testing environment. It was just a way to get kind of the same timing behavior in the repro. You can just chain up the original componentDidLoad in the repro to avoid clobbering the lifecycle? It's hard to give a robust repro case for this because it's a race condition and depends on timing.

@jcfranco
Copy link
Member

Gotcha. I'll reach out to get a closer look at the test failures.

Hope we can find a repro case. Otherwise, we'll have to put this in the back burner until the Stencil lifecycle issue is fixed.

@jcfranco
Copy link
Member

jcfranco commented Aug 1, 2023

[belated] @jkieboom provided an updated (internal) repro case for this. He also confirmed it's not critical, so we'll be moving this to a later milestone (after the Stencil v4 update as the disconnectedCallback was recently fixed).

@jcfranco jcfranco self-assigned this Dec 8, 2023
@jcfranco jcfranco added 2 - in development Issues that are actively being worked on. and removed 0 - new New issues that need assignment. labels Dec 8, 2023
@jcfranco
Copy link
Member

jcfranco commented Dec 8, 2023

Tested locally, and this is still an issue w/ [email protected] (without any specific fixes for this).

@jcfranco
Copy link
Member

jcfranco commented Dec 8, 2023

Narrowed down the issue to this line. We store the initial overflow style to restore it when modal is closed, which is only correct for the first modal that opens. Subsequent ones will store the style that the modal applies, hence why overflow: hidden lingers after all modals are removed in a different order. I managed to create a repro case showing this.

@driskull
Copy link
Member

driskull commented Dec 8, 2023

Makes total sense! nice find

@driskull
Copy link
Member

driskull commented Dec 8, 2023

Sounds like a registry of modals could handle this.

jcfranco added a commit that referenced this issue Dec 12, 2023
…n multiple modals are closed/removed (#8390)

**Related Issue:** #6594 

## Summary

We store the initial overflow style to restore it when modal is closed,
which is only correct for the first modal that opens. Subsequent ones
will store the style that the modal applies, so the incorrect overflow
value is applied after all modals are removed in a different order.

This updates modal to store the initial overflow style only for the
first modal that is open. This will ensure the correct initial overflow
style is restored when all modals have been closed.
@jcfranco jcfranco added 3 - installed Issues that have been merged to master branch and are ready for final confirmation. and removed 2 - in development Issues that are actively being worked on. labels Dec 12, 2023
@github-actions github-actions bot assigned geospatialem and DitwanP and unassigned jcfranco Dec 12, 2023
Copy link
Contributor

Installed and assigned for verification.

@DitwanP
Copy link
Contributor

DitwanP commented Dec 12, 2023

🍡 Verified locally on main

@DitwanP DitwanP closed this as completed Dec 12, 2023
@DitwanP DitwanP added 4 - verified Issues that have been released and confirmed resolved. and removed 3 - installed Issues that have been merged to master branch and are ready for final confirmation. labels Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - verified Issues that have been released and confirmed resolved. ArcGIS Maps SDK for JavaScript Issues logged by ArcGIS SDK for JavaScript team members. bug Bug reports for broken functionality. Issues should include a reproduction of the bug. estimate - 3 A day or two of work, likely requires updates to tests. impact - p3 - not time sensitive User set priority impact status of p3 - not time sensitive p - medium Issue is non core or affecting less that 60% of people using the library
Projects
None yet
Development

No branches or pull requests

5 participants