Closed Bug 1766145 Opened 2 years ago Closed 9 months ago

Can't refresh page by hitting Enter in urlbar if there's a URL fragment, because docshell assumes we want same-document navigation

Categories

(Firefox :: Address Bar, enhancement)

Desktop
Unspecified
enhancement

Tracking

()

RESOLVED DUPLICATE of bug 1239653
Tracking Status
firefox101 --- affected

People

(Reporter: aminomancer, Unassigned)

References

Details

Attachments

(1 file)

STR

  1. First try going to this link
  2. Click the urlbar and hit Enter
  3. Doc reloads
  4. Now go to this link
  5. Click the urlbar and hit Enter
  6. Nothing happens, because same-document navigation only scrolls to the named anchor "updating"

This is obviously intended behavior in a manner of speaking, because the implementation is really low level and just cares about the load states. It's just checking if the destination URI equalsExceptRef the current URI. This is what we want generally, so that we can click named anchor links to jump to the headings, as in the table of contents I linked.

But with respect to the urlbar, I think we want something a bit different. When we click a named anchor link it's unlikely that it will do nothing, because the named anchor link is unlikely to be at the same scroll position as the heading to which it links. But in the urlbar it's trivially easy for us to trigger a load that does nothing: we just have to click the urlbar and hit Enter.

If we typed a different fragment after the hash then again, it would make sense to use the same-document navigation handler. But if the urlbar value is identical to the current doc spec, and the scroll position hasn't changed, the same-document navigation handler will do nothing. So this can feel like a bug to some users (see here for example).

I have two ideas for resolving this. The first and simpler, I already implemented to make a custom script for that person who first reported this. Basically, in gURLBar._loadURL we check if url === browser.currentURI.spec and where === "current" and if so, we go into a different path where our ultimate browser.loadURI call will pass the LOAD_FLAGS_IS_REFRESH flag. So that means pressing Enter in the urlbar when its value equals the current URL will always cause the navigation to reload.

However, that isn't a perfect solution. What happens if we go to the second link and then scroll down a bunch, and then hit Enter so we can get back up to the original heading? Well Firefox currently just does nothing. But with the first proposed change, this would trigger an unnecessary reload. How do we know whether the user wants a full reload, or just anchor navigation?

I would propose that we move this change from the javascript to the docshell code, and in there we add a special case within same-document navigation that yields to a normal URI load:

  1. It's not history navigation
  2. URIs are the same including hash
  3. Needed scroll position is the same as current scroll position

I'm not sure exactly how to implement #3 but I can see that the resources exist for us to compare the two from within nsDocShell::InternalLoad. Anyway, it seems like that would be the ideal solution. But I already have a patch for the easier javascript approach, so I'm gonna submit it as WIP in case anyone wants to see how that works in practice.

And by the way, I'm wondering if anyone knows why hitting Enter in the urlbar doesn't work for scrolling to the anchor position. Like if you click the 2nd link and scroll down the page, then click the urlbar and hit Enter, it doesn't set the scroll position back to the heading. I wasn't able to find the cause. It seems weird since that means hitting Enter in the urlbar literally does nothing when there's a hash in the URL and there's no user typed value. Whereas if we replace the fragment with something else, it does scroll of course.

I know I'm proposing that we change that behavior anyway, but it would be useful to know why that's not working since it would come into play with my 2nd proposed method — which would effectively scroll to the heading if not already scrolled to it, and reload the page otherwise.

This is a javascript approach to resolving bug 1766145. It's not ideal,
since it will still refresh the page even if we've scrolled away from
the original anchor position. So a better solution would only reload if
the scroll positions already match. But I'm not sure how to do that yet
and I did all of this before I thought of it. So I figured I'd submit
this as WIP so it can be referenced while considering the alternative.

Shane, thanks for filing this. This is similar to https://bugzilla.mozilla.org/show_bug.cgi?id=778399, and this bug was resolved as INVALID.
The other bug is more general and is about refreshing the page when any fragment is loaded.

Also note that a simple workaround is to refresh the page (ctrl-r).

We'll look into the UX implications raised by this bug.

See Also: → 778399
Status: NEW → RESOLVED
Closed: 9 months ago
Duplicate of bug: 1239653
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: