W3C home > Mailing lists > Public > whatwg@whatwg.org > November 2009

[whatwg] AJAX History Concerns

From: Brady Eidson <beidson@apple.com>
Date: Thu, 12 Nov 2009 09:12:19 -0800
Message-ID: <DCFF2990-A25F-4D4B-9C8F-605312A403A1@apple.com>

On Nov 11, 2009, at 11:24 PM, Marius Gundersen wrote:

> I'm not exactly sure what you mean in the first case. How is the title change hidden from the DOM? When you call document.title = "new title", then the title does change in the DOM and in the UI.

Sure, that's my point.  You're talking about the DOM API to title, but I'm talking about the new API that says the title you pass in the function calls is "purely advisory."

So if you do:

document.title = "Old title";
replaceState("state object", "New title", "http://example.com/index.html?2");
alert(document.title);

What does the alert show?

The current back/forward entry would says "New title" in most (all?) modern browsers.  But the actual title of the document, as exposed to the DOM, is still "Old title"

This seems inconsistent and silly.

> About your second question, I think you misunderstood it. As you said, it says:
> "Then, if the current entry was removed in the previous step, the current entry must be set to the last entry for that Document object in the session history."
> 
> In other words, the last entry in the session history must now equal what was the current entry. It's just worded a bit confusingly.

I agree it's confusing.  I don't see how you're right here, though.

Imagine the following session history.  3 documents - A, B, and C.  Each have more than one entry because they're all using this hawt new API:

A1 - A2 - B1 - *B2* - B3 - C1 - C2

In this scenario, B2 is the current entry.

"When this method is invoked, the user agent must remove from the session history all the entries from the first state object entry for that Document object up to the last entry that references that same Document object, if any."

So If a script on document B calls "clearState()", then quite clear, entries B1, B2, and B3 will be removed.

Oh no, the current entry was removed!  So, now what is the current entry?  This is most certainly where it gets confusing:

"Then, if the current entry was removed in the previous step, the current entry must be set to the last entry for that Document object in the session history."

The Document object in question is B.  B1, B2, and B3 were just removed.  There is no "last entry for that Document object" because we just removed them all.  In my original message I liberally interpreted this to mean the new current entry should be a copy of "B3" but without the state object because, clearly, we just "removeState()"ed.  Which would leave us the following:

A1 - A2 - *B3* - C1 - C2

I'm not saying this is correct, but it's my best following of the described procedure.  Your interpretation is that the list should be:

A1 - A2 - C1 - C2 - B2

That seems insane to me.  We've never given scripts the ability to arbitrarily re-order the back/forward list before, and I don't think we should start now.  Even pushState() carefully preserves the ordering of documents A - B - C.  

What you're proposing is that document B can "cut in line" in front of document C's entries in the list.  It seems to me that malicious and/or downright rude site developers could abuse this to always keep themselves "on top" of the back/forward list, breaking the UI expectations of what those little left/right arrows mean.


> A better way of saying it would be:
> 
> "Then, if the current entry was removed in the previous step, the current entry must now be pushed onto the session history". 

That wording would be very clear, but I don't think that's at all what the current language is intending.  

Also, if that was the actual intent and wording, I would object (see discussion above).

~Brady

> 
> Marius Gundersen
> 
> 
> On Thu, Nov 12, 2009 at 12:48 PM, Brady Eidson <beidson at apple.com> wrote:
> For reference see section 6.10.2 of the spec.
> 
> In getting an implementation for pushState(), replaceState(), and clearState() going I've had a few concerns.
> 
> pushState() and replaceState():
> 
> When pushState() or replaceState() are called with a URL argument, the document's current address is changed.  This has a lot of side effects in that it is exposed to scripts and the DOM and most modern user agents would update their UI to show this.
> 
> However, this same section takes care to point out "The title is purely advisory. User agents might use the title in the user interface."  Indeed, many user agents would show the title of the current page at the top of the browser window or tab, in their back/forward list, and possibly in their global persistent history.
> 
> But unlike the URL which actually changes in the Document object and is therefore exposed to the DOM, this "purely advisory" title change is hidden from the DOM.  I'm questioning the reasoning behind this distinction and am curious if it was intentional or not.
> 
> clearState():
> 
> The following text describes clearState():
> 
> "When this method is invoked, the user agent must remove from the session history all the entries from the first state object entry for that Document object up to the last entry that references that same Document object, if any.
> 
> Then, if the current entry was removed in the previous step, the current entry must be set to the last entry for that Document object in the session history."
> 
> Imagine the following scenario:
> 
> A document has 5 state entries.
> They each have a different URL as follows:  http://www.example.com/page.html?1, http://www.example.com/page.html?2, http://www.example.com/page.html?3, http://www.example.com/page.html?4, and http://www.example.com/page.html?5
> The current entry is the 3rd entry.
> A script calls "clearState()" so these entries are all cleared out, including the current entry.
> Since the current entry was removed, the current entry after the clearState() call is changed to be the last entry for the Document.
> 
> My reading of the spec is that after clearState() returns, the entries 1-4 will be gone completely, the state object for entry 5 will have been cleared, and entry 5 will now be the current entry.
> 
> This has the side effect of the URL for the current entry - http://www.example.com/page.html?5 - not matching the current URL of the document - http://www.example.com/page.html?3
> 
> Is my understanding of what the current entry should be correct?
> If not, what am I missing?
> And is the disjoint between the Document's URL and the current entries URL correct?
> If not, what am I missing?
> 
> Thanks,
> ~Brady
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20091112/6fbc11f2/attachment-0001.htm>
Received on Thursday, 12 November 2009 09:12:19 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:19 UTC