4 ms·
> If it makes sense to "open in new tab" then it should be a link. Otherwise it's a button. The problem is that apparently, an infuriating number of Front end
by FridgeSeal 4y ago
> If it makes sense to "open in new tab" then it should be a link. Otherwise it's a button.
The problem is that apparently, an infuriating number of Front end devs seem to think that nothing in their shouldn’t-have-been-an-SPA page should ever be a link and go somewhere, preferring instead to waste an equivalent amount of time popping up some modal or changing page anyway.
- aidenn0 4y agoBut a lot of times they have a useful routing library (even if by accident) that updates the URL, so opening a new tab with the update URL actually does something useful, but it's not a link so I can't do that.
- Gigachad 4y agoUgh, its an annoying problem that I understand from both sides. Opening a new page has a surprisingly large amount of user friction vs opening a sidesheet or modal. Most of it is just a deficiency in how browsers work. If I'm scrolling down a listing page, I don't want to open a new page because returning will often leave me not where I was before. So I make a judgement call on if a link is _really_ worth clicking. While pages which allow expandable previews or modals, I am much more likely to click since its less of a disruption.
- 8ytecoder 4y agoReturning/navigating back absolutely takes you back exactly where you were. It’s broken because the whole page is now being rendered in js and that forces a re-render. SPA misuse has ruined web to the extent we’ve forgotten what it was like to have proper navigation before all the history hijacking and complete rerendering jazz.
- jameshart 4y agoOn the other hand, after opening a bunch of tool windows and documents to copy-paste between in photoshop or blender or whatever, users don’t expect a ‘back button’ to take them back to the previous window layout state. They might expect a back button to navigate among which window is in the foreground, or between view/zoom positions. Consider the possibility that some web applications might actually benefit from acting more like that.
- 8ytecoder 4y agoWhy I said SPA misuse and not use of SPA.
- yakshaving_jgt 4y ago> If I'm scrolling down a listing page, I don't want to open a new page because returning will often leave me not where I was before. Have you actually tried doing that on this very website you are now reading? Click on my profile. Then click back. Where are you? When I tested this just now, I was returned to exactly the point in the page where I left it.
- iggldiggl 4y agoIt works reliably for pages that don't do any client-side-rendering – in that case the browser reliably knows when it has finished loading and layouting all the content and can then restore the scroll position. Things become more iffy with client-side rendering, because the browser has no clear signal to decide when page-loading has progressed far enough that it can try to restore the previous scroll position.
- yakshaving_jgt 4y agoRight. So do less client-side rendering. The internet does way too much client-side rendering, for no reason whatsoever.
- Gigachad 4y agoThat's not going to happen. It's much easier to open a model or sidesheet than use server side rendering. I imagine in future generations of frameworks and browsers, we will be able to do SPAs without the issues we currently see.
- yakshaving_jgt 4y agoI really don’t think it is. You then need to account for: - all the extra styling complexity - the history API - memory management (sometimes) Etc.
- tshaddox 4y agoThis is a very popular criticism of SPAs, but every time I see it I really gotta ask how people are screwing this up and if it actually has anything to do with SPAs. With every even slightly popular way I know of to develop SPAs, you have to go out of your way to make links not work as normal links.
- edflsafoiewq 4y agoYou don't make a single page application by adding links to other pages.
- tshaddox 4y agoSure you do. You use the Link component (or similar) that’s provided by the SPA router, which renders a normal <a href="cool-page"> tag that works fine with middle-clicking, command-clicking, and right-clicking. The only difference is that it overrides the click event to perform a client-side navigation on normal clicks. You have to go out of your way to make this not work, or I suppose you could implement your own SPA framework and not understand how any of this works.
- chrismorgan 4y agoI’ve never liked the <Link> approach. I much prefer to write normal links throughout and intercept clicks globally, which is easier to work with, and every bit as reliable (more, in some situations). See https://news.ycombinator.com/item?id=31366875 https://news.ycombinator.com/item?id=31366875 for some discussion of this approach, with sample code in https://news.ycombinator.com/item?id=31373486 https://news.ycombinator.com/item?id=31373486.
- tshaddox 4y agoYeah, that works well too, it just isn't as common in component-based frameworks for the reasons pointed out in that thread.