seed icon indicating copy to clipboard operation
seed copied to clipboard

Seed shouldn't intercept links with `target` attribute

Open MartinKavik opened this issue 5 years ago • 7 comments

See https://github.com/seed-rs/seed/blob/38f6c201206b9988abf60d9c399383e3734a6414/src/browser/service/routing.rs#L101

Should we ignore all links with set target or only with some target values (e.g. _self)?

MDN docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a


Workaround:

orders.subscribe(|subs::UrlRequested(url, url_request)| {
    if should_not_intercept_this_url(url) {
        url_request.handled()
   }
});

MartinKavik avatar Jul 15 '20 09:07 MartinKavik

Hey, why should we ignore it ?

Here is the quote from the doc :

target Where to display the linked URL, as the name for a browsing context (a tab, window, or

    _self: the current browsing context. (Default)
    _blank: usually a new tab, but users can configure browsers to open a new window instead.
    _parent: the parent browsing context of the current one. If no parent, behaves as _self.
    _top: the topmost browsing context (the "highest" context that’s an ancestor of the current one). If no ancestors, behaves as _self.

arn-the-long-beard avatar Feb 16 '21 11:02 arn-the-long-beard

When you write attrs!{ At::Target => "_blank" }, then you hope the link will be opened in a new tab. However Seed doesn't ignores it (if the link has a relative URL) and handles it as a regular link / route => it behaves exactly like _self instead of _blank.

P.S. There are also other exceptions that should be handled - e.g. when the user holds Control key during the click, it should open a new tab, but it doesn't happen because Seed handles it as a regular link click.

MartinKavik avatar Feb 16 '21 17:02 MartinKavik

But why can't it open a new tab?

mankinskin avatar Feb 16 '21 18:02 mankinskin

But why can't it open a new tab?

Seed intercepts all relative links by default to prevent the app reloading. The intercepted link click doesn't propagate to the browser's handler so it doesn't process the link at all in such cases. Taking things like target="_blank" into account is basically a missing Seed feature.

MartinKavik avatar Feb 16 '21 19:02 MartinKavik

Ah, okay. Now I understand. I wonder what should happen with the other target values. Does seed have a concept for these "browsing contexts"? None that I am aware of. A simple solution to this problem might be to just stop intercepting any relative link calls with target=_blank but the other target values would still not be handled correctly.

But maybe that is just fine? I am not sure what a "browsing context" could be other than a browser page or an iframe. So I guess to handle target properly, seed needs to provide some story for tabs and iframes.

mankinskin avatar Feb 16 '21 19:02 mankinskin

I would just handle the most common cases - it means Ctrl key + click and target="_blank". We can add special handling for other cases when somebody needs it - I would try to respect YAGNI.

Does seed have a concept for these "browsing contexts"? None that I am aware of.

There aren't any special concepts / apis for "browsing contexts".

MartinKavik avatar Feb 16 '21 21:02 MartinKavik

Makes sense. I guess anything the other targets do can be emulated using other features.

mankinskin avatar Feb 16 '21 21:02 mankinskin