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

attachBrowserEvent is triggered twice #240

Closed
martinr92 opened this issue Dec 2, 2014 · 11 comments
Closed

attachBrowserEvent is triggered twice #240

martinr92 opened this issue Dec 2, 2014 · 11 comments

Comments

@martinr92
Copy link

Hello UI5-Developers,

I've got the problem, that every keydown event is triggered twice.
Please take a look at the short example.
JSBin

Always when you press one key, the counter cntr variable is increased 2 times.
Do you have any idea, how to fix this?

Thanks for your help.
Greetings
Martin

@akudev
Copy link
Contributor

akudev commented Dec 2, 2014

Hi Martin,
you should not register this kind of handler in onAfterRendering because it can and will be called multiple times and you never deregister, so you get more and more listeners.
When you register in the onInit function of the controller, it works as expected:
http://jsbin.com/vokofukalu/1/edit

However, the straightforward deduction that onAfterRendering is called twice here does not apply. It is only called once (otherwise it would in fact be a performance bug). However, this means that I don't have an explanation yet why your listener is called twice when attached in onAfterRendering...

This needs further analysis.

Andreas

@martinr92
Copy link
Author

Hi Andreas,
Thanks for your fast response and the great solution.
Moving the handler registration in the onInit function works pretty well.

@akudev
Copy link
Contributor

akudev commented Dec 2, 2014

Hi Martin,
glad that we were able to help you!
But I'd still like to see this behavior understood. -> reopening

Andreas

@akudev akudev reopened this Dec 2, 2014
@akudev
Copy link
Contributor

akudev commented Dec 2, 2014

Ok, the issue is that the browser event handlers are detached before rerendering and re-attached after rendering. However, when you register in onAfterRendering, the handler is 1.) immediately attached and 2.) re-attached by the RenderManager, so this is where the duplicate registration comes from.

This is indeed a bug. Thanks for spotting this!
Internal reference: 1472004194.

@simlin
Copy link
Contributor

simlin commented Jan 16, 2015

The issue should be solved in master and 1.26.4 via the following commits:
c317049
f879f16

@simlin simlin closed this as completed Jan 16, 2015
@akudev akudev added fixed and removed in progress labels Jan 16, 2015
@cheungkonghou
Copy link

it's happening again in v.1.40.8... I simply put a console.log inside onAfterRendering and it's called twice.

@codeworrior
Copy link
Member

Is onAfterRendering called twice (which can happen depending on the scenario) or is the event handler indeed attached twice?

@cheungkonghou
Copy link

simply something like this:
onAfterRendering: function(){ console.log('controller onAfterRendering'); ... },

@codeworrior
Copy link
Member

Well, that's most likely normal behaviour. See #1162 (comment) for a description of the rendering process. As explained there, any control (or view) might be rendered multiple times if there are updates to its configuration.

If you think there is indeed a problem, we need a more detailed description of the scenario, ideally as a JSBin. And if so, I would propose to open a new issue as yours seems not to be immediately related to the duplicate attachBrowserEvent that was discussed here.

@cheungkonghou
Copy link

My case is: I use an XML view with some native html elements in it (using xhml namespace), and then I'll use some 3rd party plugins on those elements. However those elements got inited again when the view is re-rendered. Is there any solution to achieve this?

@cheungkonghou
Copy link

Moreover I am confused that when I use a IconTabBar to switch between tabs, the tab content got re-rendered again but no onBeforeRendering or onAfterRendering event is sent...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants