-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve embeds and fix Firefox problems with the scroll position on media preview #689
Conversation
add an id to the `a` element of an entry in a list. That leads to firefox being able to jump to the correct position on the site when going back. That is mostly a problem when auto media preview is enabled
- when an entry is created and the url is fetched for any embedded stuff, it previously got discarded. Save it in the db now - add additional fields to save title, description, image and html returned from the fetched embed
don't want to be a stick in the mud again but I'm not too on board with storing fetched embed data (especially html) in the db:
also, if you still want to store the fetched embed html in the db anyway, It'd be great if you could split that changes into a new PR: with the first problem you identified and wanted to fix, not only this change does not answer that problem, this is a different problem perceived with potentially its own solutions altogether, tacking them into the same PR/unit of changes is ... not good if I wanted to be even more pedantic, the "add ids to links so firefox could come back" and "immediately render embed in twig when auto preview is enabled" could be split into 2 more patches since it answer a slightly different problems, but I can let it slide with how the current problem could be described as a combination of those two problems together, like:
if this is the thing you're trying to fix, it's quite hard to see that how storing embed in db help solving that problem |
Yeah I always put too much stuff into one PR your right. Mostly its related by topic or by problems created by doing something in a new way, but yeah I can see that it should have been 2-3 PRs. Regarding the storing: for images I totally get it, they can change (although I doubt they change that often but that is only my gut feeling)
The biggest problem with a ttl on an embed are because of the initial rendering with it: Maybe I can just do the link id stuff and see how this is behaving. If that already fixes most of my problem when browsing on my phone (where I have auto preview enabled) then the other changes are not needed. |
I think the main problem is that we cannot say how often an embed changes. Html iFrame element probably never change, images probably change only very rarely, I'd say the url on a post changes when the image changes (mostly) |
namespace App\Controller; | ||
|
||
use App\Repository\EmbedRepository; | ||
use App\Utils\Embed; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; | ||
use Symfony\UX\TwigComponent\Attribute\PostMount; | ||
|
||
#[AsTwigComponent('embed', template: 'components/embed.html.twig')] | ||
class EmbedController extends AbstractController |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a twig component though? it should go in App\Twig\Components
(src/Twig/Components/EmbedComponent.php
) and unless you somehow also need this to act as a controller it shouldn't extend the AbstractController
and be named appropiately
namespace App\Controller; | |
use App\Repository\EmbedRepository; | |
use App\Utils\Embed; | |
use Psr\Log\LoggerInterface; | |
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; | |
use Symfony\UX\TwigComponent\Attribute\PostMount; | |
#[AsTwigComponent('embed', template: 'components/embed.html.twig')] | |
class EmbedController extends AbstractController | |
namespace App\Twig\Components; | |
use App\Repository\EmbedRepository; | |
use App\Utils\Embed; | |
use Psr\Log\LoggerInterface; | |
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; | |
use Symfony\UX\TwigComponent\Attribute\PostMount; | |
#[AsTwigComponent('embed', template: 'components/embed.html.twig')] | |
class EmbedComponent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right 👍
the main reason I brought up the image storage is less of that they may change, but rather the need/desire to store caches of almost all remote contents for basically forever, and right now we sort of ended up in a situation where we can't clear the remote image caches out cleanly because many parts has assumed that the backing image will always exists also, even when the image content change, that should results in a different image content hashes and our image system seem to be handling that case fairly well
agree on this, however with the current way embed are fetched and used, there's no similar guarantees or a good way to tell differences between what current remote content and our cached copy is, or if there's any you could say that I'm arguing for one specific edge case here, but I feel like this one edge case is also where the difference is potentially way more obvious to the users when it happens: enter github gists, it looks like these can be updated after first publish to a certain extent, you may see something like "last updated ago", along with the revision list showing the changes when viewing some gists and while the "github recommended" way of getting embed gist is to use
and hence my concern about storing the embed html into db that's fetched once and never again, because it assumes that the content at one url never changes although that may not be the case
I think I can understand this point, though with this and the above concern, it might be a good idea to add some kind of background embed cache update, similar to the actor auto update system, though I guess we might ended up running into the same problem as #620 but in a different place 😅 also it appears that it's possible to async recompute the symfony cache going by this docs and it's also possible to make a cache pool backed by doctrine dbal, but from intial skimming it looks like the amout of additional setup to add may not be too different from doing it manually so might as well continuing down the manual path since you already got some of it in
I think this conversation here is a good example case on one of the reasons why one should avoid making a PR that tries to fix multiple problems at once: the initial problem of this PR was this:
but instead of getting to focus on the problem or the potential solution that fixes the stated problem, here I am going on another raving "old way or highway" on a different but only tangentially related problems instead, but I couldn't simply ignore it because it also needs to be reviewed |
actually, do you have any explanations, docs or keywords to search on why adding ids to links help with reliably restoring navigation position? this feels like magic or (ab)using firefox quirks to get this done more than a proper "fix", but if it works it works, and if it must need this vendor specific workaround then so be it (there's another firefox specific workaround some where else in this project so I could understand the needs) |
I agree with asdfzdfj that I don't think storing embed in the DB is a good idea. If we store bad data, we store it forever |
The weird thing is I'm a firefox user with infinite scrolling on and never ran into any problems entering entries and hitting the back button. I just turned on auto media preview and I still don't have any issues, all the previews are still there and my view is exactly where I was before |
Your |
Sadly I don't have anything concrete. My guess is that firefox remebers on which element I clicked and if it has an id it stores that somehow in the history. I just tinkered with it and this worked...
What would I change to 301s? |
Ok, I already decided to take it out from this PR and put in another one where we can discuss it 👍 |
Though it was happening to me on my local dev environment as well, so I am not sure... I am using Fennec on mobile, maybe I should try vanilla FF for it... |
Please read my comment here #689 (comment) I did this testing with the same Firefox instance, kbin.run does 3 requests in 42ms and your site does 71 requests in 3.21s. I feel like the answer to the problems you face is figuring out why it makes any requests at all when hitting the back button |
if that's the case then it's even weirder: 200s of static content should have been the easiest content to cache |
It is cached and it says it got the content from cache. But Firefox having the requests in the console at all means that it basically reloads the site instead of using the last site it has in the cache. |
You know what's great... It is mercure... I had it enabled and it is disabled on kbin.run |
No me gusta mercure |
On my phone the problem is not fixed by this, so maybe it is a Fennec specific issue? (I have the same problem on kbin.run with auto media preview). |
I see now only 3 requests hitting back on your site. That's crazy that just disabling mercure does that. Maybe we're messing something up with how we load mercure in the page and it's causing the DOM to not cache (obviously the images respond with cached as asdfzdfj pointed out but it showing up vs not at all in network confuses me)? |
Well it is caching correctly, but it essentially forces a page reload... |
Yea, sorry, edited comment, I just meant from a perspective of the network requests showing up at all, cached or not, I'm not sure if it's the DOM not being reusable or what, I guess I'm not an expert at this stuff, so won't comment on it further |
merde*, I think I have idea why:
note that I might be off here, but this is the closest thing I could think of * somehow this sound came up in my head upon reading that |
But the |
Don't know if it works, but would this be better: connect() {
this.es(this.getTopics());
window.onpagehide = function (event) {
if (window.es !== undefined) {
window.es.close();
}
};
const c = this;
window.onpageshow = function () {
c.es(c.getTopics());
}
} |
in any case I spawned a new issue to track that in #696, I'll see what I could do for that (at the very least is to change from |
Just confirmed that only #696 is the problem, so I am going to close this |
When using firefox and automatic media preview was enabled the scroll position was never reliably restored. So when you would browse the entry list and then open an entry and then navigate back you would most likely end up on the bottom of the page, because our links did not have an id and the previews were expanded after the site was loaded.
So what this PR does: