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

SchedulerTooltip mouseOffset stack overflow #7283

Closed
chuckn0rris opened this issue Aug 9, 2023 · 1 comment
Closed

SchedulerTooltip mouseOffset stack overflow #7283

chuckn0rris opened this issue Aug 9, 2023 · 1 comment
Assignees
Labels
bug Something isn't working forum Issues from forum large-account Reported by large customer OEM OEM customer premium resolved Fixed but not yet released (available in the nightly builds)
Milestone

Comments

@chuckn0rris
Copy link

Forum post

In my React app with Bryntum 5.4.2 when I set

scheduleTooltipFeature={{
  mouseOffsetX: 0,
  mouseOffsetY: 0,
}}

then I get these stack overflow errors:

Uncaught RangeError: Maximum call stack size exceeded
    at get containingWidget [as containingWidget] (Widget.js:4734:1)
    at get isVisible [as isVisible] (Widget.js:4064:1)
    at get isVisible [as isVisible] (Widget.js:4064:1)
    at get isVisible [as isVisible] (Widget.js:4064:1)
    at Tooltip.realign (Widget.js:3056:1)
    at Tooltip.realign (Tooltip.js:802:1)
    at Tooltip.alignTo (Tooltip.js:833:1)
    at Tooltip.realign (Widget.js:3065:1)
    at Tooltip.realign (Tooltip.js:802:1)
    at Tooltip.alignTo (Tooltip.js:833:1)

RangeError: Maximum call stack size exceeded
    at Rectangle.clone (Rectangle.js:365:1)
    at Rectangle.alignTo (Rectangle.js:776:1)
    at Object.alignTo (Widget.js:2786:1)
    at Object.alignTo (Tooltip.js:833:1)
    at Object.realign (Widget.js:3065:1)
    at Object.realign (Tooltip.js:802:1)
    at Object.alignTo (Tooltip.js:833:1)
    at Object.realign (Widget.js:3065:1)
    at Object.realign (Tooltip.js:802:1)
    at Object.alignTo (Tooltip.js:833:1)

The error disappears with:

scheduleTooltipFeature={{
  mouseOffsetX: 0,
  mouseOffsetY: 6,
}}

@chuckn0rris chuckn0rris added bug Something isn't working premium forum Issues from forum large-account Reported by large customer OEM OEM customer labels Aug 9, 2023
@chuckn0rris
Copy link
Author

Introducing hasOffset into alignTo method of Tooltip class will fix the problem for almost all cases

    alignTo(spec) {
        const
            me = this,
            {
                mouseOffsetX,
                mouseOffsetY
            }  = me,
            hasOffset = mouseOffsetX | mouseOffsetY; // <<<< here 

        if (!me.isVisible) {
            return;
        }

        let mousePosition;

        if (!me.anchorToTarget && spec.position === 'mouse') {
            mousePosition = new Point(
                me.triggeredByEvent.pageX - globalThis.scrollX,
                me.triggeredByEvent.pageY - globalThis.scrollY
            );
            spec.position = new Point(
                mousePosition.x + me.mouseOffsetX * (me.rtl ? -1 : 1),
                mousePosition.y + me.mouseOffsetY
            );
        }

        // If mouse pointer is over this, do not attempt
        // to call the getHtml method.
        if (spec && !(me.triggeredByEvent && me.element.contains(me.triggeredByEvent.target))) {
            //<debug>
            if (!(spec.nodeType || spec.target || spec.position || spec.domEvent || spec.event || (spec instanceof Point))) {
                throw new Error('alignTo must be either passed a target to position by, or a position Point to position at');
            }
            //</debug>
            if (spec.nodeType === Node.ELEMENT_NODE) {
                spec = {
                    target : spec
                };
            }
        }

        super.alignTo(spec);

        // If the mouse comes within 5 pixels of our result position, flip the mouseOffsets to the opposite sides
        if (hasOffset && mousePosition && me.lastAlignSpec.result.inflate(5).contains(mousePosition)) { // <<<< here 
            me.lastAlignSpec.position = 'mouse';
            me.mouseOffsetY = -mouseOffsetY - me.height;
            me.mouseOffsetX = -mouseOffsetX - me.width;
            me.realign();
            me.mouseOffsetY = mouseOffsetY;
            me.mouseOffsetX = mouseOffsetX;
        }
    }

@ExtAnimal ExtAnimal self-assigned this Aug 14, 2023
@ExtAnimal ExtAnimal added in progress ready for review Issue is fixed, the pull request is being reviewed resolved Fixed but not yet released (available in the nightly builds) and removed in progress ready for review Issue is fixed, the pull request is being reviewed labels Aug 14, 2023
@SergeyMaltsev SergeyMaltsev added this to the 5.5.2 milestone Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working forum Issues from forum large-account Reported by large customer OEM OEM customer premium resolved Fixed but not yet released (available in the nightly builds)
Projects
None yet
Development

No branches or pull requests

3 participants