kaboom icon indicating copy to clipboard operation
kaboom copied to clipboard

Every sprite image loads twice in Safari

Open kuzmaka opened this issue 3 years ago • 2 comments

Version

No response

What browsers are you seeing the problem on?

Safari

What happened?

Any sprite loads twice in Safari browser. Highly likely, it happens due to the following lines of code in kaboom.ts:

// wrapper around image loader to get a Promise
function loadImg(src: string): Promise<HTMLImageElement> {
	const img = new Image();
	img.src = isDataURL(src) ? src : assets.urlPrefix + src;   // first load
	img.crossOrigin = "anonymous";                                      // second load
       ...

What's the expected behavior?

Each sprite should load only once in any browser including Safari.

Minimum reproducable code

kaboom()

loadSprite('test', 'test.png')  // it doesn't matter if image file actually exists

Live demo

No response

kuzmaka avatar Jul 08 '22 04:07 kuzmaka

Hmm, so strange, @slmjkdbtl check it when you can!

lajbel avatar Jul 21 '22 23:07 lajbel

Btw, when I swap these two lines of code then issue disappears:

	img.crossOrigin = "anonymous";    // no src  url yet, so no load possible
	img.src = isDataURL(src) ? src : assets.urlPrefix + src;   // first load

kuzmaka avatar Jul 22 '22 04:07 kuzmaka

Very weird, but yeah your fix does work, thanks! The change is merged to master.

slmjkdbtl avatar Sep 28 '22 01:09 slmjkdbtl