[Bug 11468] spec logic: replaceState before onload should not affect onload object or popstate should not fire after onload.

http://www.w3.org/Bugs/Public/show_bug.cgi?id=11468

henry.fai.hang.chan@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |henry.fai.hang.chan@gmail.c
                   |                            |om

--- Comment #1 from henry.fai.hang.chan@gmail.com 2010-12-04 14:50:08 UTC ---
A webapp alters all its links to use ajax to load the page.  To ease url
sharing, it uses popstate.  To maintain backwards compatibility, the same pages
are served by pasting in the popstate url.

Consider Example [1]: fetchAjax ignores NULL
1. A user goes to index.html
2. DOM ready fires and the links are assigned an onclick handler "loadLink",
calls pushState with a state object of the new url, and calls "fetchAjax" to
fetch the page using ajax.
3. "fetchAjax" is registered to onpopstate so that it will fetch the ajax page
on a history traversal.
4. The onload event fires.
5. The onpopstate event fires.
6. "fetchAjax" does not fetch any page as the event state is NULL.
7. The user clicks on a link page1.html.
8. The "loadLink" function is called, triggering a pushState and then
fetchAjax.
9. The user clicks on a link page2.html.
10.The "loadLink" function is called, triggering a pushState and then
fetchAjax.
11.The user clicks back on his browser.
12.The opnpopstate even fires, with a event state of page1.html.
13.The fetchAjax fetches page1.html.
14.The user clicks back on his browser again.
PROBLEM:
15.The onpopstate even fires, with a event state of NULL.
16.index.html is not fetched, but the url is now 'index.html'
CAUSE: The handler cannot distinguish between first page load and back and
forth page load as both have the event state of NULL.

Consider Example[2]:
1. A user goes to index.html
2. DOM ready fires and the links are assigned an onclick handler "loadLink",
calls pushState with a state object of the new url, and calls "fetchAjax" to
fetch the page using ajax.
3. "fetchAjax" is registered to onpopstate so that it will fetch the ajax page
on a history traversal.
4. The user clicks a link to page1.html before onload is fired.
5. The onload event fires.
6. The onpopstate event fires.
PROBLEM:
7. index.html is refetched AND the URL stays on page1.html.
8. Going back refetches index.html.
9. Going forward refetches page1.html.

Workaround [1]: Use Example 1, but fetch location.href when event state is
null.
PROBLEM: An ugly flash of content and reloading of images because onpopstate is
called after onload.

Workaround [2]: Use Workaround[1], but add a variable on onload that causes the
first onpopstate to return instead of fetching page.
PROBLEM: What if user aborts the page after dom ready fires but before onload?

Workaround [3]: Use Workaround[1], but add a variable on document parsing
(wrong term?) that causes the first onpopstate to return instead of fetching
page.
PROBLEM: Extra variables and overhead.

Workaround [3]: Fire replaceState on first onpopstate / onload.
PROBLEM[a]: If a user clicks a link page1.html, a pushState is fired.  When
onpopstate / onload fires, the history becomes [index.html, index.html].
index.html is refetched. page1.html disappears totally from the history.
PROBLEM[b]: If a user navigates to page1.html then page2.html, then
onpopstate/onload fires, the history becomes [index.html, page1.html,
index.html].

Workaround [4]: Fire replaceState during document parsing. (wrong term?)
This works in Google Chrome.  window.onpopstate calls with a null event state.
Navigating to a new page and then clicking back will fire event with new event
state.
PROBLEM: Starting with firefox 4b8pre (some build a few days ago), replaceState
caused the window.onload event to fire with the replaced event state.  Causes
same effect as Example 2.

Workaround [5]:
Remember the time for onpopstate and the time for onload.  If the difference is
less than 200 milliseconds abort the onpopstate.
PROBLEM: unreliable.


Solution [1]:
  Don't fire onpopstate after onload.  Most simplest, but rejected in bug
10365.
Solution [2]:
  Queue the events up by the UA.
  PROBLEM: Back and forward doesn't work before onload fires, what if user
aborts page load?
Solution [3]:
  Fire onpopstate after onload with a null event state, regardless of whatever
replaceState.  And allow replaceState to call before document finishes loading.

-- 
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Saturday, 4 December 2010 14:50:11 UTC