iron-meteor / iron-layout

Dynamic layout with support for rendering dynamic templates into regions.
MIT License
46 stars 11 forks source link

"You called beginRendering again before calling endRendering", different cause #7

Closed doctorpangloss closed 10 years ago

doctorpangloss commented 10 years ago

I'll build the repro later today, but here's the bug:

Throws "You called beginRendering again before calling endRendering" error:

Router.map(function () {
    this.route('landingPage', {
        path: '/',
        action: function () {
            if (Meteor.user()) {
                this.redirect(nonreactiveFunctionThatGivesMeAPath());
            } else {
                this.render();
            }
        }
    });
});

Does not throw error, does the same thing:

Router.map(function () {
    this.route('landingPage', {
        path: '/',
        waitOn: function() {
            // Gets the user data
            return Meteor.subscribe('me');
        },
        action: function () {
            // Wait until I actually have data
            if (this.ready()) {
                // Now check if I'm logged in, non-reactively
                var user;
                Deps.nonreactive(function() {
                    user = Meteor.user();
                });
                if (user) {
                    this.redirect(nonreactiveFunctionThatGivesMeAPath());
                } else {
                    this.render();
                }
            } else {
                this.render();
            }
        }
    });
});
cmather commented 10 years ago

Thanks for reporting. This is probably a bit of a debugging exercise. I'll clone your repo when you have it and take a look. Thanks for doing that!

doctorpangloss commented 10 years ago

I can actually bug it out by doing a redirect in an action, period full stop, as long as I'm using anything reactive. My workaround is below.

        action: function () {

            if (this.ready()
                && Meteor.user()) {
                Meteor.defer(function() {
                    Router.go(nonreactiveFunctionThatGivesMeAPath(), {replaceState: true});
                });
            }

            this.render();
        }
cmather commented 10 years ago

Hey @doctorpangloss, A repro would be really helpful. This seems like it could be something that affects a lot of people so would prefer to fix the root issue. Do you have a github project I can take a look at? Doesn't need to be perfect.

doctorpangloss commented 10 years ago

Yeah I'm having trouble reproing it exactly. Just documenting my notes here. Thanks a lot, maybe I'll be able to fix it :)

cmather commented 10 years ago

Ok thanks. I just tried to reproduce this bug and was unable on devel (commit: 7993938). Also, just double checked that the controller should call the finishCurrentRenderingTransaction method before calling beginRendering() again. From a quick glance of the code I'm not sure how beginRendering could get called again before the finishCurrentRenderingTransaction is called. Are you on the latest devel commit?

doctorpangloss commented 10 years ago

Alright I can repro different bugs, I'm posting it to the right place now