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

Injection race condition #12

Closed
protodave opened this Issue Jun 25, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@protodave
Contributor

protodave commented Jun 25, 2014

From the Iconic forums:
https://useiconic.com/community/#!/tools:inject-safety-iconicjs-v0

We currently using iconic with our angularjs app.

In order to support dynamically added icons, we turned off the auto-inject selector, and have a directive to inject the iconic icon.

We originally had the auto-inject selector enabled together with our directive, but found a race condition where the auto-injection would still be running when the directive would start ‘injecting’; this would fail in the replaceChild call within iconic.min.js as the icon had already been processed.

We are finding another race condition, with a similar problem, where the directive might fire off multiple times and inject the same icon twice on the same element, failing with the same ‘replaceChild’ error.

Can you look at adding a check before injecting an icon to make sure it still needs injecting?

Note: This issue is in SVGInjector, on which iconic.js is built.

@protodave

This comment has been minimized.

Show comment
Hide comment
@protodave

protodave Jun 25, 2014

Contributor

Initial thoughts on a solution...

  • Maybe something like adding a data-injecting="true" flag to the img tag when injection first triggers for that element to keep any subsequent calls from also trying to inject it?
  • Or just simply see if that element even still exists on the page before trying to replaceChild it (though it might be best to skip the additional network call for the SVG in the first place via the semaphore solution).

Other options?

Contributor

protodave commented Jun 25, 2014

Initial thoughts on a solution...

  • Maybe something like adding a data-injecting="true" flag to the img tag when injection first triggers for that element to keep any subsequent calls from also trying to inject it?
  • Or just simply see if that element even still exists on the page before trying to replaceChild it (though it might be best to skip the additional network call for the SVG in the first place via the semaphore solution).

Other options?

@stryju

This comment has been minimized.

Show comment
Hide comment
@stryju

stryju Jun 25, 2014

Contributor

my current solution: write a small provider that you could configure, and refer to it from the directive (think of it as a queue)

as soon as the iconic itself would support providing element as \an argument for inject, this would be improved as well, but for now it's more like

  • directive link
  • provider inject iconic with a small timeout (100ms works for me)

if you need a full solution, let me know ;-)

Contributor

stryju commented Jun 25, 2014

my current solution: write a small provider that you could configure, and refer to it from the directive (think of it as a queue)

as soon as the iconic itself would support providing element as \an argument for inject, this would be improved as well, but for now it's more like

  • directive link
  • provider inject iconic with a small timeout (100ms works for me)

if you need a full solution, let me know ;-)

@protodave

This comment has been minimized.

Show comment
Hide comment
@protodave

protodave Jul 1, 2014

Contributor

Now keeping track of elements that are already being injected so any subsequent calls to inject that same element are skipped.

Contributor

protodave commented Jul 1, 2014

Now keeping track of elements that are already being injected so any subsequent calls to inject that same element are skipped.

@protodave protodave closed this Jul 1, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment