Project

General

Profile

How to debug "Wt internal error; code: undefined, description: Cannot read property 'add' of undefined"

Added by Emeric Poupon over 3 years ago

Hello,

I have an annoying error: when loading the application on a specific URL, I get this popup: "Wt internal error; code: undefined, description: Cannot read property 'add' of undefined".

As the generated corresponding code is quite huge, how can I properly debug this? How do you usually proceed?

Note this popup only appears when my "page" has a very limited amount of content. If it has a lot of content, I don't hit this issue.

Regards,


Replies (3)

RE: How to debug "Wt internal error; code: undefined, description: Cannot read property 'add' of undefined" - Added by Emeric Poupon over 3 years ago

Actually, I used a js code "beautifier" and it looks like it is related to the "infinite scroll" loading I recently added:

Generated code:

Wt._p_.response(1876239405); {
    Wt4_2_0.ScrollVisibility = function(g) {
        function l(a) {
            if (a.style.visibility == \""
                hidden\ "" || a.style.display == \""
                none\ "" || $(a).hasClass(\""
                    out\ "")) return false;
            else return (a = a.parentNode) && !n.hasTag(a, \""
                BODY\ "") ? l(a) : true
        }

        function o(a, c) {
            if (!l(a)) return false;
            var e = n.widgetPageCoordinates(a),
                d = e.x - document.body.scrollLeft - document.documentElement.scrollLeft;
            e = e.y - document.body.scrollTop - document.documentElement.scrollTop;
            var f = n.windowSize(),
                r = a.offsetHeight,
                p = -c,
                s = f.x + 2 * c,
                q = -c;
            c = f.y + 2 * c;
            return d + a.offsetWidth >= p && p + s >= d && e + r >= q && q + c >= e
        }

        function h() {
            if (i)
                for (var a in b) {
                    if (b.hasOwnProperty(a)) {
                        var c = l(b[a].el);
                        if (b[a].visibleIfNotHidden && b[a].visible !== c) {
                            b[a].visible = c;
                            g.emit(b[a].el, \""
                                scrollVisibilityChanged\ "", c)
                        }
                    }
                } else
                    for (a in b)
                        if (b.hasOwnProperty(a)) {
                            c = o(b[a].el, b[a].margin);
                            if (c !== b[a].visible) {
                                b[a].visible = c;
                                g.emit(b[a].el, \""
                                    scrollVisibilityChanged\ "", c)
                            }
                        }
        }

        function t(a) {
            for (var c = 0; c < a.length; ++c) {
                var e = a[c],
                    d = e.target,
                    f = d.id;
                d = l(d);
                if (e.intersectionRatio > 0 || e.intersectionRect.top !== 0 || e.intersectionRect.left !== 0) {
                    b[f].visibleIfNotHidden = true;
                    if (b[f].visible !== d) {
                        b[f].visible = d;
                        g.emit(b[f].el, \""
                            scrollVisibilityChanged\ "", d)
                    }
                } else {
                    b[f].visibleIfNotHidden = false;
                    if (b[f].visible) {
                        b[f].visible = false;
                        g.emit(b[f].el, \""
                            scrollVisibilityChanged\ "", false)
                    }
                }
            }
        }

        function u() {
            if (j) {
                j.observe(document, {
                    childList: true,
                    attributes: true,
                    subtree: true,
                    characterData: true
                });
                if (!i) {
                    window.addEventListener(\""
                        resize\ "", h, true);
                    window.addEventListener(\""
                        scroll\ "", h, true)
                }
            } else m = setInterval(h, 100)
        }

        function v() {
            if (j) {
                j.disconnect();
                if (!i) {
                    window.removeEventListener(\""
                        resize\ "", h, {
                            capture: true
                        });
                    window.removeEventListener(\""
                        scroll\ "", h, {
                            capture: true
                        })
                }
            } else if (m) {
                clearInterval(m);
                m = null
            }
        }
        var n = g.WT,
            k = 0,
            b = {},
            i = false,
            j = null,
            m = null;
        if (window.hasOwnProperty(\""
                MutationObserver\ "")) j = new MutationObserver(h);
        this.add = function(a) {
            k === 0 && u();
            var c = a.el.id,
                e = c in b;
            i && e && b[c].observer && b[c].observer.disconnect();
            var d = o(a.el, a.margin);
            if (a.visible !== d) {
                a.visible = d;
                g.emit(a.el, \""
                    scrollVisibilityChanged\ "", d)
            }
            b[c] = a;
            if (i) {
                d = new IntersectionObserver(t, {
                    rootMargin: \ ""\
                    "" + a.margin + \""
                    px\ ""
                });
                d.observe(a.el);
                b[c].observer = d
            }
            e || ++k
        };
        this.remove = function(a) {
            if (k !== 0) {
                if (a in b) {
                    i && b[a].observer && b[a].observer.disconnect();
                    delete b[a];
                    --k
                }
                k === 0 && v()
            }
        }
    }\

I followed the wt example and did this to replace a "show more" button: https://github.com/epoupon/lms/commit/36ccd62a846a2c9bb073911e9d9a0785fbbb2541#diff-517166f603943540b469114f31aa8745

RE: How to debug "Wt internal error; code: undefined, description: Cannot read property 'add' of undefined" - Added by Emeric Poupon over 3 years ago

I get another meaningful error using firefox: "Wt internal error; code: undefined, description: Wt4_2_0.scrollVisibility is undefined"

So now the question is: what am I doing wrong? :(

RE: How to debug "Wt internal error; code: undefined, description: Cannot read property 'add' of undefined" - Added by Emeric Poupon over 3 years ago

Ok I read more carefully the documentation and now instead of using setHidden on the sentinel widget, I just create/delete it.

It works fine now.

    (1-3/3)