Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 396400

Summary: BrowserHistoryEvent not fired anymore after page reload
Product: [RT] RAP Reporter: Claudio Guglielmo <claudio.guglielmo>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: ivan
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Claudio Guglielmo CLA 2012-12-12 08:24:20 EST
We use the browser history to navigate to certain points in the application. This works fine as long as the user reloads the page or visits another page and comes back. After doing so, pressing back in the browser has no effect anymore.

It can be reproduced in the rap examples: Go to http://rap.eclipsesource.com/rapdemo/examples, then go to TableViewer and afterwards to Complex Data. Hit reload and step back 3 times. The browser location bar now shows http://rap.eclipsesource.com/rapdemo/examples#tableviewer but the content still is "complex data".

Reason: After a reload, no BrowserHistoryEvent will be fired anymore when pressing back. The source of the problem is in History.js: In __startTimer there is a check which ignores states which are not in _titles. Since reloading the page recreates the history object, _titles is empty and therefore the former titles are lost. Removing the check solves the issue, but then the window title does not get updated anymore. 
I also tried to add the history entries again after a reload. This makes the back button work but also adds duplicate entries to the browser history, which we don't want either. It's probably necessary to somehow sync the entries after a reload.

This functionality is important to us because we would like to keep the state of the application independent of the rap session, see also Bug 387360.
Comment 1 Ivan Furnadjiev CLA 2012-12-12 08:43:39 EST
I think that this is a duplicate of bug 394401, which has been fixed in master and will be part of the 4-th milestone.

*** This bug has been marked as a duplicate of bug 394401 ***
Comment 2 Claudio Guglielmo CLA 2012-12-12 09:05:05 EST
Thanks for the fast reply! You're right, the other bug is related, didn't see that sorry. 

According to your commit at https://github.com/eclipse/rap/commit/f7e19ae28127543f8adac7fa287d23520effdb35, you only removed the check "this._titles[ newHash ] != null", right? It's exactly what I did too at first, but unfortunately it's not sufficient in my opinion. The code at __onHistoryLoad sets the document title. If _titles is empty, the title will be wrong. Or am I missing something?

__onHistoryLoad : function(state) {
  this._state = state;
  this.createDispatchDataEvent("request", state);
  if (this._titles[state] != null) {
    document.title = this._titles[state];
  }
},
Comment 3 Ivan Furnadjiev CLA 2012-12-12 09:20:11 EST
(In reply to comment #2)
> Thanks for the fast reply! You're right, the other bug is related, didn't
> see that sorry. 
> 
> According to your commit at
> https://github.com/eclipse/rap/commit/
> f7e19ae28127543f8adac7fa287d23520effdb35, you only removed the check
> "this._titles[ newHash ] != null", right? It's exactly what I did too at
> first, but unfortunately it's not sufficient in my opinion. The code at
> __onHistoryLoad sets the document title. If _titles is empty, the title will
> be wrong. Or am I missing something?
> 
> __onHistoryLoad : function(state) {
>   this._state = state;
>   this.createDispatchDataEvent("request", state);
>   if (this._titles[state] != null) {
>     document.title = this._titles[state];
>   }
> },

Yes, you are right... the navigation will work, but the browser title will not be as before (will contain the initial RAP application title and will not change till entry is put into the array again) as _titles array will be empty.
Comment 4 Claudio Guglielmo CLA 2012-12-13 11:12:11 EST
Ok. Shall I reopen the other bug?
Comment 5 Ivan Furnadjiev CLA 2012-12-13 11:20:31 EST
(In reply to comment #4)
> Ok. Shall I reopen the other bug?

I don't think that we can do anything about the titles.
Comment 6 Claudio Guglielmo CLA 2012-12-13 11:34:27 EST
(In reply to comment #5)
> (In reply to comment #4)
> > Ok. Shall I reopen the other bug?
> 
> I don't think that we can do anything about the titles.

Ok, no problem.
Comment 7 Ivan Furnadjiev CLA 2012-12-13 15:22:05 EST
(In reply to comment #6)
> Ok, no problem.
You could use the new JavaScriptExecutor service to set the title back in the navigation event.