Cannot read property 'replace' of undefined when clicking browser back // production only bug
See original GitHub issueHey guys, I think this is the right place to post this, please correct me if I’m wrong. I recently deployed a meteor project to this url
After loading the root url and programmatically routing to another path (with FlowRouter.go
), then clicking the browser’s back button this error pops up.
Uncaught TypeError: Cannot read property 'replace' of undefined
I deployed the project with the --debug flag and the error occurs in the _.each
block with path.replace
on line 435…
Router.prototype.initialize = function () {
function initialize() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (this._initialized) {
throw new Error('FlowRouter is already initialized');
}
var self = this;
this._updateCallbacks(); // Implementing idempotent routing
// by overriding page.js`s "show" method.
// Why?
// It is impossible to bypass exit triggers,
// because they execute before the handler and
// can not know what the next path is, inside exit trigger.
//
// we need override both show, replace to make this work
// since we use redirect when we are talking about withReplaceState
_.each(['show', 'replace'], function (fnName) {
var original = self._page[fnName];
self._page[fnName] = function (path, state, dispatch, push) {
if (!self.env.reload.get() && self._current.path === path) {
return;
}
`path = path.replace(/\/\/+/g, '/'); // 435`
original.call(this, path, state, dispatch, push);
};
}); // this is very ugly part of pagejs and it does decoding few times
// in unpredicatable manner. See #168
// this is the default behaviour and we need keep it like that
// we are doing a hack. see .path()
this._page.base(this._basePath);
this._page({
decodeURLComponents: true,
hashbang: !!options.hashbang
});
this._initialized = true;
}
return initialize;
}();
When the back button is clicked, the route path (in the url bar) changes to the correct path, but the corresponding template does not render.
This bug can be reproduced by going to this url, clicking “save me money”, then clicking the browser back button.
On the shop insurance template there’s an X with a click event including FlowRouter.go('/')
Weirdly enough, after clicking that X when the error is thrown, the root url template loads and then the error won’t happen again until you refresh the browser.
Note: everything works as intended locally, this only happens in production
Any help would be much appreciated, and if you need any more details please let me know!
Thanks, Dylan
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (11 by maintainers)
Top GitHub Comments
Hey @dylanmcgowan , I’m glad to help 😃 This is the long one ))
This issue took time to poke around. Thanks to community, Open Source, and @derwaldgeist . Do you ever imagine how this could be solved under close environments. Damn! I love Open Source (IMHO it should be always be written starting with capital letters)!
Feel free to close it once you will successfully update package, and your issue will be gone.
Yes I am using that
okgrow:analytics
package! Thank goodness I was loosing my mind over here. Thanks so much @dr-dimitru you’ve been such a massive help 😃