You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Explore using selector-observer to run features #3084
GitHub uses selector-observer to enable logic on simple classes, which is why adding or removing classes like .js-fit-content will enable or disable their features.
Let’s avoid any more conversions to selector-observer for the time being. There are some outstanding drawbacks we need to solve first. For example:
it always automatically waits for domready, so it’s not as fast as one using element-ready.
sometimes it should be disabled on deinit, like for that recent feature to remove labels.
some features should only be applied when the elements are visible (I have some code about this in the first related PR)
We should find a common, efficient way to cover all of these issues. Either via code or via documentation (e.g. “if feature requires X, then you must use deinit”)
it always automatically waits for domready, so it’s not as fast as one using element-ready.
I don't have a strong feeling about this so I can't say anything.
sometimes it should be disabled on deinit, like for that recent feature to remove labels.
I think most of the time this could be solved with carefully chosen selectors.
some features should only be applied when the elements are visible (I have some code about this in the first related PR)
Are you referring to this one? May worth try implementing it again, but I can't think of a feature that could make use of it for the moment.
I can see you are continuing the discussion in #3514, I'm also aware of the issue but didn't jump in yesterday because my thoughts are not clear. Now I'll just put in my two cents:
I'm not familiar with all existing and pending usage of selector-observer, but I would say it is definitely useful for dealing with ajaxed components. For sure we don't want to convert every feature into using it, but I think our original intention is to fix bugs which will be hard/verbose without it. Take my two open PR converting into selector-obsever as an example, I think there's a good reason to use it.
Existing usage like linkify-user-edit-history-popup and remove-label-faster may be rewritten to reduce the usage of selector-observer (judge from a glance, correct me if I'm wrong).
In short, if a feature works well, we don't need to use selector-observer. If the code is nice without selector-observer, we can remove the use of it. If a feature has a bug that selector-observer can solve with ease, we should favor it. This is just my own humble opinion though.
Yes, I used that function for a couple of features. But yes, it's probably not useful in many cases.
It doesn't need to be rewritten, it worked well, it only lacked :not(.rgh-class) but I did not have time to investigate back then.
Existing usage like linkify-user-edit-history-popup and remove-label-faster may be rewritten to reduce the usage of selector-observer (judge from a glance, correct me if I'm wrong).
I think those are exactly the features that are fine with selector-observer
linkify-user-edit-history-popup needs complicated listeners for the popup, and doesn't benefit from element-ready because it appears well after dom-ready
remove-label-faster affects the sidebar, which is:
a ajaxed "hot zone"
loaded last on the page, so element-ready wouldn't save a lot of FOUC
In short, if a feature works well, we don't need to use selector-observer
Only until we sort this out. There are some features that are a mess of listeners and could benefit from selector-observer’s simplicity.
What do you think about this? 👇
Edit: maybe too wordy
Always use selector-observer when...
... the feature affects a number of elements across the page and they're in ajaxed "hot zones" e.g. parse-backticks can find elements to modify anywhere on the page. element-ready would not have any advantages here.
Always use element-ready when...
... the feature only affects a specific part of the page and it's not in an ajaxed "hot zone" (e.g. conversation header and sidebar, and list of files)
For the rest of them...
... perhaps select.all is enough
... we need to evaluate whether it's worth giving up "faster features" (#2671) in exchange for reliability.
if the selector has :not(.rgh-this-feature) and we add the class right away, selector-observer will no longer call the add method because the original selector no longer applies. This avoids the loop.
We almost always do that already, but #3517 didn't because it didn't seem necessary.
Activity
fregante commentedon Jul 16, 2020
Many of the bugs currently open can be fixed with this, so I really hope that someone can figure it out.
fregante commentedon Aug 29, 2020
Let’s avoid any more conversions to selector-observer for the time being. There are some outstanding drawbacks we need to solve first. For example:
deinit, like for that recent feature to remove labels.We should find a common, efficient way to cover all of these issues. Either via code or via documentation (e.g. “if feature requires X, then you must use deinit”)
fregante commentedon Aug 29, 2020
cc @yakov116 @kidonng
kidonng commentedon Aug 29, 2020
I don't have a strong feeling about this so I can't say anything.
I think most of the time this could be solved with carefully chosen selectors.
Are you referring to this one? May worth try implementing it again, but I can't think of a feature that could make use of it for the moment.
I can see you are continuing the discussion in #3514, I'm also aware of the issue but didn't jump in yesterday because my thoughts are not clear. Now I'll just put in my two cents:
I'm not familiar with all existing and pending usage of selector-observer, but I would say it is definitely useful for dealing with ajaxed components. For sure we don't want to convert every feature into using it, but I think our original intention is to fix bugs which will be hard/verbose without it. Take my two open PR converting into selector-obsever as an example, I think there's a good reason to use it.
Existing usage like
linkify-user-edit-history-popupandremove-label-fastermay be rewritten to reduce the usage of selector-observer (judge from a glance, correct me if I'm wrong).In short, if a feature works well, we don't need to use selector-observer. If the code is nice without selector-observer, we can remove the use of it. If a feature has a bug that selector-observer can solve with ease, we should favor it. This is just my own humble opinion though.
fregante commentedon Aug 29, 2020
That may be right. Do you want to try reverting #3476?
Yes, I used that function for a couple of features. But yes, it's probably not useful in many cases.
It doesn't need to be rewritten, it worked well, it only lacked
:not(.rgh-class)but I did not have time to investigate back then.I think those are exactly the features that are fine with
selector-observerlinkify-user-edit-history-popupneeds complicated listeners for the popup, and doesn't benefit fromelement-readybecause it appears well afterdom-readyremove-label-fasteraffects the sidebar, which is:element-readywouldn't save a lot of FOUCOnly until we sort this out. There are some features that are a mess of listeners and could benefit from
selector-observer’s simplicity.What do you think about this? 👇
Edit: maybe too wordy
Always use
selector-observerwhen...... the feature affects a number of elements across the page and they're in ajaxed "hot zones" e.g.
parse-backtickscan find elements to modify anywhere on the page.element-readywould not have any advantages here.Always use
element-readywhen...... the feature only affects a specific part of the page and it's not in an ajaxed "hot zone" (e.g. conversation header and sidebar, and list of files)
For the rest of them...
... perhaps
select.allis enough... we need to evaluate whether it's worth giving up "faster features" (#2671) in exchange for reliability.
fregante commentedon Aug 29, 2020
I'll try rewriting that:
"Ajaxed hot-zones" are areas that have nested ajaxed widgets and require a number of listeners and mutation observers to detect changes.
selector-observerforked-toonly affects links in the header: Useelement-readyselect.allfregante commentedon Sep 9, 2020
Urgent debugging wanted
Further features and refactoring using
selector-observerwon't be accepted until we know how to avoid this from happening.cc @kidonng @yakov116 this is why I temporarily closed related PRs.
yakov116 commentedon Sep 17, 2020
https://github.com/kylekyle/monitoring what about this? It's actively maintained and it looks like it runs before dom ready too!
Another good thing is.
Which means we can stop the observer on some features after all the elements loaded.
yakov116 commentedon Sep 21, 2020
@fregante should I try https://github.com/kylekyle/monitoring and play around with it? Or do you want to stick to select-observer?
fregante commentedon Sep 21, 2020
We need to verify those 3 points first, there's no point in changing library if has the same issue (or if the issue doesn't exist)
fregante commentedon Sep 25, 2020
I confirmed the bug and found a workaround:
:not(.rgh-this-feature)and we add the class right away,selector-observerwill no longer call theaddmethod because the original selector no longer applies. This avoids the loop.We almost always do that already, but #3517 didn't because it didn't seem necessary.
@kidonng you can resubmit ImproveImprovecleanup-repo-filelist-actions’s reliability #3517 with the workaround describedcleanup-repo-filelist-actions’s reliability #3531 already exists 👍linkify-code, which is the heaviest feature making use ofselector-observerfregante commentedon Sep 25, 2020
@yakov116 if you also want to look into any other features that use
selector-observerbut don't have this class, please send a PR for that