flying-focus icon indicating copy to clipboard operation
flying-focus copied to clipboard

multiple instances on one page

Open notslang opened this issue 11 years ago • 6 comments

If I have the flying focus chrome plugin installed and I visit a site that uses the flying focus script, 2 instances of flying focus run on the same page. This creates 2 separate elements (both with the id flying-focus) and they are both animated.

The fact that this happens doesn't actually break anything (they just overlap), and it's not really a performance concern since it's such a light plugin. Rather, it simply feels wrong to have 2 of them running at the same time, especially since both of the elements created have the same id.

So, flying-focus should check if the #flying-focus element has already been created, and exit if it has, to prevent multiple instances.

notslang avatar Dec 27 '13 09:12 notslang

The extension used to check #flying-focus: flying-focus.jspp.js#L2. I removed when I implemented lazy initialization flying-focus.js#L32-L35, e.g. the flying-focus element gets created on first focus event. In this situation race conditions happen.

I haven’t seen any websites besides mine using the script so I don’t think it isn’t very important issue as for now.

NV avatar Dec 27 '13 23:12 NV

JS is inherently single-threaded, so one of the instances is bound to create the element first, right? Eh, anyway, you're right - it isn't a big issue.

notslang avatar Dec 27 '13 23:12 notslang

The problem is that flying-focus.js can be initialized either before or after the extension, depending on where script element is (head or end of the body).

NV avatar Dec 27 '13 23:12 NV

exactly, so whichever happens first gets to continue running, the other just stops. it doesn't matter whether the extension or script is the one that is running, it's just whichever is first.

On Fri, Dec 27, 2013 at 5:13 PM, Nikita Vasilyev [email protected]:

The problem is that flying-focus.js can be initialized either before or after the extension, depending on where script element is (head or end of the body).

— Reply to this email directly or view it on GitHubhttps://github.com/NV/flying-focus/issues/7#issuecomment-31284514 .

notslang avatar Dec 27 '13 23:12 notslang

CodeCombat is using it right now, and I see the issue. (I don't mind it at all; just adding an example of a site that uses it.)

nwinter avatar Jan 02 '14 04:01 nwinter

@slang800, that would work. I don’t have much time to test but I’ll accept a pull request.

@nwinter nice, I’m a fan! I just listed it on newly created In the Wild wiki page.

NV avatar Jan 02 '14 04:01 NV