Skip to content
Closed
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
2 changes: 0 additions & 2 deletions site/gatsby-srr.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from "react";

export const onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<script key="svg-js" src="/js/svg.min.js" async={false} />,
Expand Down
29 changes: 12 additions & 17 deletions site/src/components/ShapeBuilder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,22 @@ const ShapeBuilder = () => {
};

useEffect(() => {
const checkSVG = () => {
if (!window.SVG || !window.SVG.Element.prototype.draw) {
let retries = 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of checking once after 1 second, it will now check every 200ms for 2 seconds to avoid premature errors.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. Hmm. Hmm.

const maxRetries = 10;
const interval = 200;

const waitForSVG = () => {
if (window.SVG && window.SVG.Element.prototype.draw) {
initializeDrawing();
} else if (retries < maxRetries) {
retries++;
setTimeout(waitForSVG, interval);
} else {
setError("SVG.js or svg.draw.js plugin not loaded");
return false;
}
return true;
};

// Initial check
if (checkSVG()) {
initializeDrawing();
} else {
// If not loaded, try again after a short delay
const timer = setTimeout(() => {
if (checkSVG()) {
initializeDrawing();
}
}, 1000);

return () => clearTimeout(timer);
}
waitForSVG();

return () => {
detachKeyListeners();
Expand Down
Loading