-
Notifications
You must be signed in to change notification settings - Fork 129
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
Multiple Uppload instances have problems #180
Comments
Thanks for opening this issue, @metalgigio! I'll have a look and the problem. Maybe it's because of the direct browser usage (because it uses the global |
Thank you @AnandChowdhary ; let me know even if you find a temporary workaround. |
Is there any update on a fix/workaround for this? Having the same issue. |
This has been solved by #237. Thanks to @RichardJohnn! |
I can't believe that tiny mistake was causing this huge problem! ^.^ Fixed in 8936cc0. Big thanks! |
I should say that I think this bug still remains an issue, but the workaround, @metalgigio , was to use one instance of uppload and then each time uppload is opened, remove the previous upload event listener before adding a new one to ensure just one callback fires. |
Hi everyone, as @RichardJohnn said it does not solve the issue.
|
you will need to make sure you have one in my case I had a button with an onClick to handle opening the model myself, but before doing that i did a maybe you have one callback where you just pass in your selector like |
Thank you for ur suggest @RichardJohnn , i will try as soon as i can. |
hi,
|
The suggested workarounds are not so elegant. Investigating on this problem I have found the bug(s).
So, I introduced:
And here the code: // src/helpers/elements.ts add after the safeListen export.
/**
* Safely remove an event listener
* @param element - HTML element to remove event listener to
* @param type - Type of event listener to remove
* @param fn - Callback function to associated listener
*/
export const safeUnlisten = (
element: Element,
type: string,
fn: EventListenerOrEventListenerObject
) => {
const listener = listening.findIndex((a) => a.element === element && a.type === type);
if (listener < 0) return;
element.removeEventListener(type, fn);
listening.splice(listener, 1);
}; // src/uppload.ts
import { getElements, safeListen, safeUnlisten, compressImage } from "./helpers/elements";
...
export class Uppload implements IUppload {
id: string = `${+new Date()}`;
...
}
constructor(settings?: IUpploadSettings) {
this.settings = {};
this.updateSettings(settings || {});
this.container = document.createElement("div");
this.container.setAttribute("id", `uppload-${this.id}`);
...
}
updateSettings(settings: IUpploadSettings) {
this.settings = { ...this.settings, ...settings };
this.emitter.emit("settingsUpdated", settings);
if (settings.id) this.id = settings.id;
...
}
open() {
...
if (firstService) this.navigate(firstService);
// Replace safeListen call with:
const escape = (e) => {
if (e.key === "Escape" && this.open) {
this.close();
}
};
safeUnlisten(document.body, "keyup", escape);
safeListen(document.body, "keyup", escape);
...
}
getNavbar(sidebar = false) {
...
// Add `this.id` for radio and label.
`<input type="radio" id="uppload-service-radio-${service.name}-${this.id}" ...`
...
`label for="uppload-service-radio-${service.name}-${this.id}"`
...
}
getEffectsNavbar() {
...
// Add `this.id` for radio and label.
`<input type="radio" id="uppload-effect-radio-${effect.name}-${this.id}" ...`
`<label for="uppload-effect-radio-${effect.name}-${this.id}">`
...
} I have found more bugs and I will commit the changes in a PR. Another open issue is if const escape = (e) => {
if (e.key === "Escape" && this.open) {
this.close();
}
}; because |
Describe the bug
When having multiple istance of uppload (last versions but directly in browser) there are some issues on tab services, specially in the second istance.
To Reproduce
i made a demo in jsfidler: https://jsfiddle.net/40ntrcwf/
Try to click on "Change profile picture 2", select "choose file" and then try to switch to instagram upload.
Desktop:
The text was updated successfully, but these errors were encountered: