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
5 changes: 5 additions & 0 deletions packages/canvas/init-canvas/canvas.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script>
window.process = {
env : {}
};
</script>
Comment on lines +7 to +11
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid clobbering globals; make the polyfill minimal and browser-explicit.

Unconditionally overwriting window.process risks breaking libraries that use typeof process !== 'undefined' as a Node-runtime signal. Guard the assignment, preserve any existing env, and set process.browser = true to reduce false “Node” detections in the browser.

Apply this diff to make the polyfill non-invasive:

-    <script>
-      window.process = {
-        env : {}
-      };
-    </script>
+    <script>
+      // Minimal, non-invasive polyfill so browser code expecting process.env doesn't crash.
+      (function () {
+        var w = window;
+        var existing = (w.process && typeof w.process === 'object') ? w.process : {};
+        var env = (existing.env && typeof existing.env === 'object') ? existing.env : {};
+        // Do not overwrite existing keys; just ensure objects exist.
+        existing.env = env;
+        // Explicitly mark as browser to avoid libraries mistaking this for Node.
+        existing.browser = true;
+        w.process = existing;
+      })();
+    </script>
📝 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
<script>
window.process = {
env : {}
};
</script>
<script>
// Minimal, non-invasive polyfill so browser code expecting process.env doesn't crash.
(function () {
var w = window;
var existing = (w.process && typeof w.process === 'object') ? w.process : {};
var env = (existing.env && typeof existing.env === 'object') ? existing.env : {};
// Do not overwrite existing keys; just ensure objects exist.
existing.env = env;
// Explicitly mark as browser to avoid libraries mistaking this for Node.
existing.browser = true;
w.process = existing;
})();
</script>
🤖 Prompt for AI Agents
In packages/canvas/init-canvas/canvas.html around lines 7 to 11, the inline
script unconditionally overwrites window.process which can break libs checking
for Node; instead only create window.process if it doesn't exist, ensure
process.env is preserved or initialized to an empty object if missing, and add
process.browser = true so libraries detect a browser environment; do not remove
existing properties — merge/assign env rather than clobbering the whole object.

<!--%IMPORT_MAP%-->
<!--%IMPORT_STYLE%-->
<style type="text/css">
Expand Down