[PR #5555] [MERGED] fix(common): resolve script errors when switching sandbox modes #5257

Closed
opened 2026-03-17 02:43:22 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5555
Author: @jamesgeorge007
Created: 11/3/2025
Status: Merged
Merged: 11/4/2025
Merged by: @jamesgeorge007

Base: patchHead: fix/script-execution-sandbox-switching


📝 Commits (2)

  • 7d74f44 fix(common): resolve script errors when switching sandbox modes
  • dc16c54 refactor(common): rename MODULE_PREFIX_REGEX for clarity

📊 Changes

5 files changed (+44 additions, -13 deletions)

View changed files

📝 packages/hoppscotch-common/src/components/MonacoScriptEditor.vue (+2 -3)
📝 packages/hoppscotch-common/src/components/collections/index.vue (+6 -2)
📝 packages/hoppscotch-common/src/composables/codemirror.ts (+5 -6)
📝 packages/hoppscotch-common/src/helpers/RequestRunner.ts (+9 -2)
packages/hoppscotch-common/src/helpers/scripting.ts (+22 -0)

📄 Description

Closes FE-1046.

Scripts edited in the experimental sandbox were failing to execute when users switched back to the legacy sandbox. This happened because Monaco powered editor adds an export {}; prefix for TypeScript support, but the legacy sandbox can't handle module syntax and throws Unexpected token export.

What's changed

  • Create ~/hoppscotch-common/src/helpers/scripting.ts to centralise MODULE_PREFIX constant and utilities, alongside accounting for import path updates.
  • Strip export {}; prefix in RequestRunner.ts before executing scripts in legacy sandbox

The prefix is only stripped at execution time for the legacy sandbox - it's preserved in the underlying state, so switching back to experimental mode continues to work correctly.

Notes to reviewers

Try reproducing the issue addressed in the pre-existing implementation and validate the resolution via the steps below:

image
  • Opt out of the Experimental scripting sandbox (Legacy scripting sandbox) from settings and populate the pre/post request editor with a sample snippet.
  • Toggle the preference back (Experimental scripting sandbox), navigate back to the editor populated in the previous step and make a simple edit. For instance, inserting a new line.
  • Toggle the preference back (Legacy scripting sandbox), return to the request tab, attempt to send the request and observe the exception encountered.

Also, ensure to verify the collection exports (both individual & workspace level bulk) don't include export {};\n in the exported contents.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5555 **Author:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Created:** 11/3/2025 **Status:** ✅ Merged **Merged:** 11/4/2025 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `patch` ← **Head:** `fix/script-execution-sandbox-switching` --- ### 📝 Commits (2) - [`7d74f44`](https://github.com/hoppscotch/hoppscotch/commit/7d74f44aab2ab92107b8bf9d9db0a9628a953b2f) fix(common): resolve script errors when switching sandbox modes - [`dc16c54`](https://github.com/hoppscotch/hoppscotch/commit/dc16c548908a5e7190ac1ddfd2fe188259d7bd6c) refactor(common): rename MODULE_PREFIX_REGEX for clarity ### 📊 Changes **5 files changed** (+44 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/components/MonacoScriptEditor.vue` (+2 -3) 📝 `packages/hoppscotch-common/src/components/collections/index.vue` (+6 -2) 📝 `packages/hoppscotch-common/src/composables/codemirror.ts` (+5 -6) 📝 `packages/hoppscotch-common/src/helpers/RequestRunner.ts` (+9 -2) ➕ `packages/hoppscotch-common/src/helpers/scripting.ts` (+22 -0) </details> ### 📄 Description Closes [FE-1046](https://linear.app/hoppscotch/issue/FE-1046). Scripts edited in the experimental sandbox were failing to execute when users switched back to the legacy sandbox. This happened because Monaco powered editor adds an `export {};` prefix for TypeScript support, but the legacy sandbox can't handle module syntax and throws `Unexpected token export`. ### What's changed - Create `~/hoppscotch-common/src/helpers/scripting.ts` to centralise `MODULE_PREFIX` constant and utilities, alongside accounting for import path updates. - Strip `export {};` prefix in `RequestRunner.ts` before executing scripts in legacy sandbox The prefix is only stripped at execution time for the legacy sandbox - it's preserved in the underlying state, so switching back to experimental mode continues to work correctly. ### Notes to reviewers > Try reproducing the issue addressed in the pre-existing implementation and validate the resolution via the steps below: <img width="1906" height="565" alt="image" src="https://github.com/user-attachments/assets/af580ecd-1cbd-4d65-96f3-563eb258625c" /> - Opt out of the `Experimental scripting sandbox` (`Legacy scripting sandbox`) from settings and populate the pre/post request editor with a sample snippet. - Toggle the preference back (`Experimental scripting sandbox`), navigate back to the editor populated in the previous step and make a simple edit. For instance, inserting a new line. - Toggle the preference back (`Legacy scripting sandbox`), return to the request tab, attempt to send the request and observe the exception encountered. Also, ensure to verify the collection exports (both individual & workspace level bulk) don't include `export {};\n` in the exported contents. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:43:22 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5257
No description provided.