Opened 9 years ago
Closed 9 years ago
#34640 closed defect (bug) (fixed)
Twemoji fallback doesn't kick in on subsequent DOM mutations
Reported by: | rmccue | Owned by: | pento |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.2 |
Component: | General | Keywords: | has-patch |
Focuses: | javascript | Cc: |
Description
Fun bug I found and tracked down with @pento:
- Set an element's content via innerHTML to an emoji character
- Observe the content has been replaced with Twemoji correctly
- Set the element's content to the exact same value again
- Observe the content has been not replaced
You can try this on any page our Twemoji replacement is loaded on:
window.setInterval(function () { document.querySelector('div').innerHTML = '\ud83d\ude3d'; }, 500);
Attachments (2)
Change History (11)
#3
@
9 years ago
- Keywords 2nd-opinion has-patch added
- Milestone changed from Awaiting Review to 4.4
- Version set to 4.2
34640.diff fixes the bug, but I'd like second opinion from @azaozz or @iseulde, if they think this is the best way to go about it.
#4
@
9 years ago
That whole conditional is there to detect an image error, so if Twemoji reverts an image to text. If we add an attribute to detect the error instead, we can remove everything else in the conditional. Maybe we should also add onerror as a setting instead of patching Twemoji?
#5
@
9 years ago
Summary of the problem: if you replace an emoji image with the emoji text, we think it's an error, the observer will ignore it, and Twemoji won't parse at that time.
#6
@
9 years ago
@iseulde: Good idea, I've revised the patch so that onerror
is now an option - we can easily contribute that back upstream.
Unfortunately, we need to keep several of the checks in that conditional (need to make sure removedNodes[0]
will be defined, and that nodeName === 'IMG'
, because text nodes don't have the getAttribute()
method. I just left the conditional the same in 34640.2.diff, but if you're comfortable removing some of the checks, I'm cool with that.
#7
@
9 years ago
Ah onerror is not an option? Sorry, thought it was since all the other properties were options.
#8
@
9 years ago
- Keywords 2nd-opinion removed
Submitted upstream: https://github.com/twitter/twemoji/pull/100
With the example code, you can see Firefox will continue toggling back and forth between Twemoji and native every 0.5s; Chrome will only toggle once, then stick on native.