Skip to content
Open
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
10 changes: 10 additions & 0 deletions daisy.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@
*/
function resizeHandler() {
// resize the canvas

destroy();
//Create canvas
canvas = document.createElement('canvas');
canvas.className = 'pg-canvas';
canvas.style.display = 'block';
element.insertBefore(canvas, element.firstChild);
ctx = canvas.getContext('2d');

Comment on lines +151 to +158
Copy link

@coderabbitai coderabbitai bot Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid full destroy() on resize — it breaks the jQuery plugin handle and fires onDestroy on every resize

Calling destroy() here removes $.data('plugin_daisyjs') and triggers the onDestroy hook, so $(elem).daisyjs('pause'|'start'|...) will stop working after the first resize. Use an internal teardown variant instead.

Apply:

-      destroy();
+      // Internal teardown: keep plugin handle and skip hooks
+      destroy(true);

Optional: if you see flicker or transient errors while the canvas is detached, pause around the rebuild (cancelAnimationFrame/resume) or debounce resize with rAF.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
destroy();
//Create canvas
canvas = document.createElement('canvas');
canvas.className = 'pg-canvas';
canvas.style.display = 'block';
element.insertBefore(canvas, element.firstChild);
ctx = canvas.getContext('2d');
// Internal teardown: keep plugin handle and skip hooks
destroy(true);
//Create canvas
canvas = document.createElement('canvas');
canvas.className = 'pg-canvas';
canvas.style.display = 'block';
element.insertBefore(canvas, element.firstChild);
ctx = canvas.getContext('2d');

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maazrk kindly take a look.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

styleCanvas();

var elWidth = element.offsetWidth;
Expand Down Expand Up @@ -355,6 +364,7 @@

function destroy() {
console.log('destroy');
particles = [];
canvas.parentNode.removeChild(canvas);
hook('onDestroy');
if ($) {
Expand Down