Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/core/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ function _createLoadingOverlay(pInst) {

const currentCanvas = pInst.canvas?.elt || pInst.canvas;
if (currentCanvas) {
if (currentCanvas.parentNode && overlay.parentNode !== currentCanvas.parentNode) {
currentCanvas.parentNode.insertBefore(overlay, currentCanvas.nextSibling);
}
_positionCanvas(overlay, currentCanvas);
}

Expand Down Expand Up @@ -124,13 +127,13 @@ function _createLoadingOverlay(pInst) {

animate();
}

// Positions the loading indicator to overlay the sketch canvas
_positionCanvas(overlay, actualCanvas);


if (overlay.parentNode !== actualCanvas.parentNode) {
actualCanvas.parentNode.insertBefore(overlay, actualCanvas.nextSibling);
}

// Positions the loading indicator to overlay the sketch canvas
_positionCanvas(overlay, actualCanvas);
}

/**
Expand Down
31 changes: 31 additions & 0 deletions test/unit/core/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,37 @@ suite('Loading indicator', function () {
}
});

test('parents loading overlay again when canvas parent changes', function () {
let nextFrame;
const requestAnimationFrame = vi
.spyOn(window, 'requestAnimationFrame')
.mockImplementation(callback => {
nextFrame = callback;
return 1;
});
const newContainer = document.createElement('div');
const p = {
canvas,
_isSketchLoading: true
};

document.body.appendChild(newContainer);

try {
callCreateCanvas(p);
newContainer.appendChild(canvas);

nextFrame();

assert.strictEqual(p._loadingOverlay.parentNode, newContainer);
assert.strictEqual(p._loadingOverlay.previousSibling, canvas);
} finally {
lifecycles.postsetup.call(p);
newContainer.remove();
requestAnimationFrame.mockRestore();
}
});

test('test multiple indicators for multiple instances', async function () {
const instance1 = document.createElement('div');
const instance2 = document.createElement('div');
Expand Down
Loading