-
Notifications
You must be signed in to change notification settings - Fork 66
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
_routePageChanged running twice #129
Comments
Can you give more info here? What values of |
Whenever I click a link, _routePageChanged function is running twice. For example If I click signup link, The page value signup appears twice in console. |
It is running twice because it changes twice, because a click on e.g. /signup link triggers
Try using a one-way-binding like you do on the animated pages. |
Running a similar example and with the only two-way binding being the
|
Here's a more complete example. Switched to traditional no-hash routing as well and still getting the observer running twice. My workaround was to listen for the <link rel="import" href="bower_components/app-route/app-location.html" >
<link rel="import" href="bower_components/app-route/app-route.html" >
<dom-module id="blog-app">
<template>
<app-location route="{{route}}"></app-location>
<app-route
route="{{route}}"
pattern="/:page"
data="{{pageData}}"
tail="{{pageTail}}">
</app-route>
<ul>
<li>
<a href="/home">Home</a>
</li>
<li>
<a href="/about">About</a>
</li>
</ul>
</template>
<script>
Polymer({
is: 'example-app',
properties: {
pageData: Object
},
observers: ['_pageDataChange(pageData.page)'],
attached: function() {
window.addEventListener('location-changed', function() {
console.log('new location:' + this.pageData.page); //Fires once
}.bind(this));
},
_pageDataChange: function(e) {
console.log('_pageDataChange'); //Fires twice on route change
}
});
</script>
</dom-module> |
This is happening in Safari as well (and I suppose in all browsers). Steps to replicate:
Open Safari, show web inspector and you will immediately see:
Navigate to view2:
etc What I ended up doing to avoid this issue is this:
and changed
But it feels 'hacky' and have no idea yet what kind of problems I will be having with this. |
Not sure if this is the right strategy, but we had this problem and it was hugely affecting our page tracking. Our
|
This might be incredibly naive, but our response when having similar issues since August was to just take control of the navigator
Store data pieces or at least enough to represent last set of changes and let the data from us, user state, level etc sort of merge into an address
I don't think that what was intended here but there is a lot of memory available In the mac and rewrite back history
…Sent from my iPhone
On Dec 15, 2016, at 6:29 AM, Alan Bridger ***@***.***> wrote:
Not sure if this is the right strategy, but we had this problem and it was hugely affecting our page tracking. Our _viewChanged observer now wraps a debounce method to collapse multiple requests, which seems to have resolved the problem.
_viewChanged (view) {
this.debounce('viewChanged', () => {
// Tracking events
});
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
What's the status of the fix for this bug? I can still reproduce it on Google Chrome. |
Any update on this? I seem to have the same issue |
How it is going? |
yep how it's update ? |
I have the same buf. I'm fixed this bug by just calling routeChange and format url as i need, it is running only once on change url
|
Hi, just realised I'm also encountering this issue. Is there any update on this? |
@johnlim guess not. Maybe in Polymer 3.0? I've always said that Polymer needed a fully featured routing system complete with life cycle hooks (before callback, after callback) and maybe we'll get that in addition to a resolution to this issue. |
I've been using @abridger's |
+1 We're running into this as well. |
Still nothing new after more than one and a half year? |
Even after all these months, for reasons unknown, the 'routeData.page' is still firing twice.
` |
With Polymer 3 I'm finding the
// https://github.com/Polymer/pwa-helpers/blob/master/router.js
import { installRouter } from 'pwa-helpers/router.js';
constructor() {
super();
// Register location changed listeners
installRouter((location) => this._locationChanged(location));
}
_locationChanged(location) {
// Remove root-path from route
const prefixRegex = new RegExp('^' + this.rootPath);
// Get path from router
const path = window.decodeURIComponent(location.pathname).replace(prefixRegex, '');
// Parse path to create route
this.route = path.split('/').filter((item) => item !== '');
}
_routeChanged(route) {
// Default to '_default' when `route` array is empty.
this.page = route.length > 0 ? route[0] : '_default';
}
// Compute subroute for sub-views
// <my-view route="[[_bindSubroute(route, 'foobar')]]"></my-view>
_bindSubroute(route, uri) {
return route.length > 1 && route[0] === uri ? route.slice(1) : [];
}
// Compute active for sub-views
// <my-view active="[[_bindActive(route, 'foobar')]]"></my-view>
_bindActive(route, uri) {
return route.length > 0 && route[0] === uri;
} For query parameters, there's no end of solutions available for parsing |
This is a close ? |
Browsers Affected
Here is my code
The text was updated successfully, but these errors were encountered: