Skip to content

Conversation

@KumJungMin
Copy link
Contributor

@KumJungMin KumJungMin commented Aug 31, 2025

Defect Fixes


How To Resolve

(1) Issue (Behavior)

  • With cssTransition: false, opening OverlayPanel and clicking outside does not dismiss it.
  • Consequently hide() isn’t invoked and onExit/onExited never run.

(2) Root Cause

  • In the disabled transition path, CSSTransition fires onEnter/…/onEntered synchronously on the same tick as in changes.
  • OverlayPanel binds the outside-click listener inside onEntered, but useOverlayListener({ when: visibleState }) may still “see” the previous when=false value due to render/effect timing.

→ The bind becomes a no-op (or is immediately unbound), so outside clicks never reach hide().

(3) Fix (This PR)

  • Defer the binding to the next tick so it runs with the updated visibleState (i.e., when=true).
  • Add a guard and cancellation to avoid late binding during rapid toggle/close.
  • Also clear the timer when unbinding (onExit, hide, unmount).
    let bindOverlayTimer = null;

    const onEntered = () => {
        cancelOverlayBind();
        /**
         * With cssTransition=false, onEntered may run synchronously before visibleState updates, causing the outside-click listener not to bind.
         * Fix: defer the binding to the next tick so it runs with the latest state (when=true). (issue: #8183)
         */
        bindOverlayTimer = setTimeout(() => {
            bindOverlayListener();
        });

        props.onShow && props.onShow();
    };

    const onExit = () => {
        cancelOverlayBind();
        unbindOverlayListener();
    };

    const cancelOverlayBind = () => {
        if (bindOverlayTimer) {
            clearTimeout(bindOverlayTimer);
            bindOverlayTimer = null;
        }
    };

  • Impact/Risk: Minimal. Binding is delayed by one tick only; behavior with transitions enabled is unchanged. Timer cleanup prevents leaks and duplicate listeners.

(4) Test

cssTransition = false

before after
2025-08-31.2.30.36.mp4
2025-08-31.2.28.32.mp4

cssTransition = true

before after
2025-08-31.2.29.56.mp4
2025-08-31.2.28.57.mp4

@KumJungMin KumJungMin marked this pull request as ready for review August 31, 2025 05:38
@melloware melloware added the Type: Bug Issue contains a defect related to a specific component. label Aug 31, 2025
@melloware melloware merged commit 1aeb069 into primefaces:master Aug 31, 2025
6 checks passed
@KumJungMin KumJungMin deleted the fix/issue-8183 branch August 31, 2025 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Issue contains a defect related to a specific component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clicking outside OverlayPanel doesn't close the panel with cssTransition: false

2 participants