-
Notifications
You must be signed in to change notification settings - Fork 136
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
Need force reload to make it work on Safari #16
Comments
I use GitHub Dark and Hacker News Dark and have a similar issue. Sometimes when I go to either of these sites, the Stylish theme doesn't get applied and I see the stock theme. I have to reload (CMD+R) for it to take effect. I haven't found what causes it, but happens 1 or 2 times a day. |
My configuration:
There is a problem where the style isn't being applied. And I can 100% reproduce it:
Etc. 100% reproduced every time. So whatever is happening with the initial page load and "Cmd+R", it is not applying Stylish styles during that "page reload" event. But it is applying during the manual "reload by pressing enter on URL bar". |
@SteveJobzniak @ctrlrsf Thank you guys for reporting this issue, i'll check it soon. |
@350d Thank you. Don't worry about "soon". It is a new year. Relax and take care. :) |
Latest version 1.9.3 should cover this issue |
Unfortunately 1.9.3 didn't solve this problem, you can try it with "Baidu Lite". Safari: 10.0.3 (12602.4.8) |
ok, try 1.9.4, looks like this website updating DOM all the time. Another issue with this style - its using url prefixes and not the domain names, tabs not covered by this style, right? (these tabs: 新闻贴吧知道音乐图片视频地图文库更多» ) |
@350d Thank you so much! 💃 I downloaded 1.9.3 binary first (before 1.9.4). And followed my steps to attempt to reproduce the bug above in 1.9.3. Results:
Time to try 1.9.4 now. |
@350d I read your code for 1.9.3 and 1.9.4, and what you are doing in 1.9.4 seems great: Anytime the page DOM inserts or deletes nodes via JavaScript it checks if all styles are injected. I just hope that the "checkStyles()" call is ultra-fast. Because modern pages update the DOM a looooot and would be slowed down if checkStyles() is slow. Anyway, here are my results:
And I discovered what sometimes screws up the initial page styling even in 1.9.3+. It's some Safari bug I think... These are the steps that happen when the "unstyled initial load" happens: Open a new tab with Cmd-T, press Cmd-V to paste the URL in the URL bar, I see the URL bar briefly flicker and empty itself again and I hear a "bonk" (error sound) and the URL bar is empty, so I press Cmd-V again to paste it and now it works and the URL is filled in, and then I press Enter to go to the URL (the test URL I gave above), and then it will be unstyled. Every time the initial page load was unstyled was related to the "bonk" error sound in the URL bar of Safari, so I think it's a Safari bug. And that URL bar bug is very rare so it is no problem! Thanks for fixing the Stylish problems, it is sweet to finally see a dark YouTube skin all the time! :-) 🍔 |
ok, i've tested new method with DOMSubtreeModified and some rules to fix performance issues. Check 1.9.5 |
Nice. I see that you never react multiple times when "busy" is true (which happens when Stylish is injecting style elements). So that's good! I think we should also consider doing this, because this would be the biggest performance boost of all: var domModifiedTimer = null;
d.addEventListener("DOMSubtreeModified", function(event) {
if (domModifiedTimer) {
clearTimeout(domModifiedTimer);
}
domModifiedTimer = setTimeout([function here], 250);
});
// for [function here], use a reference to a named/static function
// (which takes zero parameters), instead of an anonymous callback,
// to avoid creating a new anonymous function 1000s of times per webpage. What this does:
|
@SteveJobzniak i'm trying to avoid setTimeouts in this case, better way is just align to requestAnimationFrame i guess. |
@350d Okay, I never heard of requestAnimationFrame, but the quick research I did now seems like it triggers when the window repaints. And DOM insertions (on well-coded sites) do not trigger repaints until all nodes are inserted. So I guess that's fine if it works! :) Why avoiding setTimeout? To avoid the small 0.25s pause in reaction time to page changes? I guess so... |
@SteveJobzniak timeouts can stack inside inactive tab for example and then fire all at once when tab is active again. |
@350d Really? Even with "clearTimeout"? The clearTimeout call happens before setTimeout, so there is only 1 active timer at a time, and the timer only gets started when DOMSubtreeModified happens. The nice thing with setTimeout is that it works even on sites that are badly coded (sites that don't code carefully to make sure that all DOM modifications happen in a single repaint). By the way, here's an idea with requestAnimationFrame:
Since Javascript is single-threaded, this will work. And this method is necessary because requestAnimationFrame callback happens 60 times per second (ouch) so it needs a fast way to check itself. Edit: I just read more (https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) and it seems requestAnimationFrame happens a single time. So it's fine to use it directly within DOMSubtreeModified with no other variables, I guess! |
Thank you man! Version 1.9.5 works fine for me now. |
I went to download Stylish 1.9.5 from the main website, but when I went to install Any ideas there? (For what it’s worth, I’m on El Cap / 10.11.6 with Safari 10.0.3, and I currently have Stylish 1.9.1 installed.) |
@handcoding sorry, can't test on El Capitan, but try to uninstall and then install the extension |
@350d Ah—that seems to have worked! Just to be on the safe side, I exported my styles before uninstalling the old version of Stylish—and I’m glad that I did since the process of uninstalling 1.9.1 and installing 1.9.5 seems to have cleared out Stylish’s settings. Oddly enough, I tried to reimport my styles, but Stylish’s Manage screen is now only showing what looks to be blank placeholder styles in each slot that used to show one of my userstyles (?). If it may help, here’s the JSON file with my styles that I exported just before uninstalling 1.9.1: |
@handcoding Try this one |
Oh, you’re a lifesaver, @350d—that worked perfectly! Can I ask what you did there in case something like this were to come up again? (Or is the problem solely because of something from 1.9.1?) |
@handcoding i should think about compatibility issues while importing from old versions. i've changed escaping for |
@handcoding compatibility fix applied in v 1.9.6 |
Right on. 👌🏼 |
This plugin is awesome on Chrome for every site I need.However this doesn't work for safari well.
Such as Material search result for Google,I can't apply the style unless I use CMD+R to reload the search page.This is very wired because it worked well on Chrome...
Safari: 9.1.1 (11601.6.17)
Mac OS X 10.11.5 (15F34)
The text was updated successfully, but these errors were encountered: