-
Notifications
You must be signed in to change notification settings - Fork 0
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
Handle appear
events
#115
Handle appear
events
#115
Conversation
try { | ||
return { | ||
...step, | ||
elements: await find(step.query), |
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.
For appear on mutation observer, I'd imagine you want the sync version rather than waiting up to a second for the element to appear.
mutations.forEach(async (mutation) => { | ||
const targets = await withElements(appearSteps); |
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.
mutations.forEach(async (mutation) => { | |
const targets = await withElements(appearSteps); | |
const targets = await withElements(appearSteps); | |
mutations.forEach(async (mutation) => { |
Seems like a performance win, no?
[...mutation.addedNodes].some((addedNode) => { | ||
if (element.contains(addedNode)) { | ||
sendStep(stepId, once ?? false); | ||
} |
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.
I'm not sure this is required at all. Don't we want basically the same logic like we do for URL events? If the DOM changed at all, and the query didn't succeed previously but now it did, then fire the appear event? Or perhaps more elaborately, we store the count of elements, then if the count is now larger than the old count we trigger the appear event?
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.
I don't see this the same way from a semantic perspective. If, by 'query succeeds', you mean both query and URL condition combined, then it can happen that the step fires even though no 'appear' took place, but purely from the technicality of the combined condition wasn't satisfied before but now is.
Practical example: we want to play something on voice when an error message first appears, as opposed to when the URL is finally compatible but the error had been around on the page for 2 minutes.
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.
Well then pre-filter the array based on URL condition, then reset it when those change?
The above code as far as I read it just triggers when an element we are targeting has a child inserted into the DOM. That could be for all sorts of reasons and doesn't necessarily mean it "appeared". For one, we are not checking its visibility, so it might not actually be visible to the user at all.
Also, why the contains
check? That could trigger an element that simply has changeable children?
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.
I had the condition backwards, just changed to addedNode.contains(element)
. This way we make sure if the user selected an element, but that is inserted as a result of its parent being inserted, then the event still fires. Otherwise, the user has to target the exact element that has been added to the DOM.
Appear intentionally does not care about visibility. There is a separate 'enters viewport' that takes care of that, and they are intentionally separate because sometimes an error notification is not visible, but you want to react to it immediately anyway.
At this point I'm tempted to say if you have a different implementation in mind, feel free to implement it as a separate PR, and we can compare.
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.
I had the condition backwards, just changed to addedNode.contains(element).
OK, that I think alleviates most of my concern here.
Appear intentionally does not care about visibility.
I believe that isn't strictly true, since the accessibility queries do care about elements being visible (at least in the they don't have display: none
set sense).
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.
I believe that isn't strictly true, since the accessibility queries do care about elements being visible (at least in the they don't have display: none set sense).
I'm ok with this edge case, but good to know for debugging.
69da7ef
to
fe2b581
Compare
} | ||
return prev; | ||
return null; |
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.
return null; |
not necessary
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.
Explicit returns read clearer to me.
fe2b581
to
a7fe029
Compare
Also includes some refactoring that fixes a click but related to the
once
feature.