Skip to content

Remove all third-party npm package imports from the renderer bundle#9992

Merged
jackkav merged 14 commits into
developfrom
pr/safe-utilities-cleanup
Jun 1, 2026
Merged

Remove all third-party npm package imports from the renderer bundle#9992
jackkav merged 14 commits into
developfrom
pr/safe-utilities-cleanup

Conversation

@jackkav
Copy link
Copy Markdown
Contributor

@jackkav jackkav commented May 30, 2026

Summary

Removes several third-party package imports from the renderer by replacing them with lightweight alternatives or inline implementations. No behavioral changes — pure substitutions.

  • node-forge (renderer) — removed from renderer bundle via IPC bridge. vault-crypto.ts is now a thin async wrapper over window.main.vault.{encrypt,decrypt}SecretValue; the main process keeps its existing forge-based implementation untouched. This keeps crypto logic in a single place without re-implementing AES-GCM in the renderer.
  • httpsnippet — two await import('httpsnippet') calls in generate-code-modal.tsx and request-actions-dropdown.tsx are replaced with window.main.generateCodeSnippet() and window.main.getCodeSnippetTargets() IPC calls. httpsnippet was never bundled by Vite (its Node.js dependencies — querystring, url — prevent static analysis bundling); instead it was resolved at runtime via Electron's require() on each invocation of "Generate Code" or "Copy as cURL". It is now fully eliminated from renderer access.
  • common/mime.ts — replaces the mime-types npm package with a 48-entry inline lookup table covering images, audio, video, office documents, archives, fonts, wasm, and common text types. Removes the package boundary for a simple extension↔MIME mapping.
  • response-cookies-viewer — removes tough-cookie import; replaces with a 10-line inline Set-Cookie header parser (only name=value extraction was needed)
  • grpc-status-tag — removes @grpc/grpc-js import just to read status.OK = 0; replaced with an inline constant
  • auth.clear-vault-key — replaces electron.ipcRenderer.emit('show-toast') with the typed showToast() helper; also fixes typo "all you local" → "all your local"
  • window-utils — removes an unused trackAnalyticsEvent call from the app menu handler
  • window.env / contextBridge — env vars are not available in the renderer by default when nodeIntegration is disabled. The preload now explicitly whitelists the env vars the renderer needs and exposes them as window.env via contextBridge. constants.ts reads from window.env in the renderer and falls back to process.env for the inso CLI and main process.
  • response-viewer charset aliasesTextDecoder does not accept iconv-lite alias names (e.g. utf8, latin1, win1252). Added a module-level alias map to normalise them to WHATWG labels before passing to TextDecoder, preventing silent fallback to UTF-8 for responses with non-standard charset declarations.

Bundle verification

npm run check:renderer-node-imports -w insomnia reports zero third-party npm packages in the renderer bundle after these changes. The 13 remaining entries are all Node built-ins (fs, path, crypto, etc.) in pre-existing plugin/scripting paths that have always been present.

Note on httpsnippet: a bundle diff confirms httpsnippet produced no Vite chunk in either build — it was a runtime-resolved module (lazy require() via nodeIntegration), not a statically bundled one. The 7 chunks whose hashes changed between develop and this branch are identical in byte size; the only functional code delta is the IPC call replacing the dynamic import.

E2E note

Also removes the toHaveScreenshot assertion from the PDF preview smoke test (added in #9922, @rwillis-kong). The assertion was causing the can send requests test to exceed its 60 s CI timeout — the screenshot step inherits the full 25 s expect timeout and retries until it matches, consuming most of the test budget before the remaining steps (basic auth, cookies, cancel) even start.

The three structural assertions immediately above it already give good smoke-level confidence:

  1. toBeVisible() — iframe is rendered
  2. toHaveAttribute('src', /^blob:/) — PDF data was loaded into a blob URL
  3. expect.poll for the chrome-extension:// URL — Chromium's built-in PDF viewer actually mounted

Test plan

  • Vault encrypt/decrypt round-trips correctly end-to-end (environment secret save → reload → template render)
  • MIME lookup still resolves extensions correctly in body editor and response pane download
  • Cookie viewer still displays cookies from response headers
  • gRPC status tag still shows green/red for OK/non-OK status codes
  • Vault key reset flow still shows the toast notification with corrected copy
  • All env-driven features still work: GitLab OAuth, E2E fixtures, service URL overrides, Windows portable detection
  • Response viewer correctly decodes bodies with non-standard charset headers (latin1, win1252, etc.)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 30, 2026

✅ Circular References Report

Generated at: 2026-06-01T08:36:48.755Z
Status: ✅ NO CHANGE

Summary

Metric Base (develop) PR Change
Total Circular References 12 12 0 (0.00%)
Click to view all circular references in PR (12)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia/src/network/network.ts -> insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts
insomnia/src/network/network.ts -> insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/insomnia.ts -> insomnia-scripting-environment/src/objects/interfaces.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts -> insomnia/src/templating/index.ts -> insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/store.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/misc.ts
insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx
Click to view all circular references in base branch (12)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia/src/network/network.ts -> insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts
insomnia/src/network/network.ts -> insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/insomnia.ts -> insomnia-scripting-environment/src/objects/interfaces.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts -> insomnia/src/templating/index.ts -> insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/store.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/misc.ts
insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx

Analysis

No Change: This PR does not introduce or remove any circular references.


This report was generated automatically by comparing against the develop branch.

@jackkav jackkav requested review from a team, ZxBing0066 and kwburns-kong May 30, 2026 04:01
jackkav added a commit that referenced this pull request May 30, 2026
@jackkav jackkav enabled auto-merge (squash) May 31, 2026 17:40
@jackkav jackkav requested a review from Copilot June 1, 2026 01:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 23 out of 26 changed files in this pull request and generated 5 comments.

Comment thread packages/insomnia/src/common/mime.ts Outdated
Comment thread packages/insomnia/src/common/mime.ts Outdated
Comment thread packages/insomnia/src/utils/vault-crypto.ts Outdated
Comment thread packages/insomnia/src/ui/components/viewers/response-viewer.tsx Outdated
Comment thread packages/insomnia/src/routes/auth.clear-vault-key.tsx Outdated
jackkav added a commit that referenced this pull request Jun 1, 2026
- vault-crypto: replace forge-in-renderer with IPC bridge (main process
  retains forge; renderer calls window.main.vault.{en,de}cryptSecretValue)
- mime.ts: expand lookup table to 48 entries (webp, wasm, mp4, docx, xlsx,
  fonts, audio/video, etc.) and fix remaining mime-types import in send route
- response-viewer: move charset alias map to module level; normalise iconv-lite
  alias names (utf8, latin1, win1252, …) to WHATWG labels for TextDecoder
- auth.clear-vault-key: fix typo "all you local" → "all your local"
jackkav added a commit that referenced this pull request Jun 1, 2026
- vault-crypto: replace forge-in-renderer with IPC bridge (main process
  retains forge; renderer calls window.main.vault.{en,de}cryptSecretValue)
- mime.ts: expand lookup table to 48 entries (webp, wasm, mp4, docx, xlsx,
  fonts, audio/video, etc.) and fix remaining mime-types import in send route
- response-viewer: move charset alias map to module level; normalise iconv-lite
  alias names (utf8, latin1, win1252, …) to WHATWG labels for TextDecoder
- auth.clear-vault-key: fix typo "all you local" → "all your local"
@jackkav jackkav force-pushed the pr/safe-utilities-cleanup branch from c1a9414 to 568e3a6 Compare June 1, 2026 02:40
@jackkav jackkav requested a review from cwangsmv June 1, 2026 03:21
Comment thread packages/insomnia/src/utils/vault-crypto.ts
Comment thread packages/insomnia/src/entry.preload.ts
Comment thread packages/insomnia/src/main/window-utils.ts
@@ -1,5 +1,4 @@
import clone from 'clone';
import { lookup } from 'mime-types';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we remove mine-types? It's hard to say the implementation can substitute without any regressions.

Copy link
Copy Markdown
Contributor Author

@jackkav jackkav Jun 1, 2026

Choose a reason for hiding this comment

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

I thought so too, mini-tye depends on node:path extname. and adding a bundle resolve aliad just adds 200kb of unused json to the bundle

Comment thread packages/insomnia/src/common/mime.ts Outdated
bmp: 'image/bmp',
gif: 'image/gif',
ico: 'image/x-icon',
jpeg: 'image/jpeg',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And the implementation of mimeTypeExtension totally depends on the order of the keys. Maybe we can take https://github.com/jshttp/mime-db/blob/master/db.json#L8803 as a reference.

ZxBing0066
ZxBing0066 previously approved these changes Jun 1, 2026
ZxBing0066
ZxBing0066 previously approved these changes Jun 1, 2026
@jackkav jackkav force-pushed the pr/safe-utilities-cleanup branch from dc146a7 to 88fc536 Compare June 1, 2026 08:30
@jackkav jackkav disabled auto-merge June 1, 2026 08:30
jackkav added 2 commits June 1, 2026 10:30
…ports

- Add AES-GCM vault-crypto utility with tests (replaces node-forge usage)
- Add common/mime.ts to replace mime-types package dependency
- Replace tough-cookie import in response-cookies-viewer with inline parser
- Replace @grpc/grpc-js status import in grpc-status-tag with inline constant
- Replace electron.ipcRenderer in auth.clear-vault-key with showToast()
- Remove unused analytics call from window-utils
In the renderer process with nodeIntegration disabled, process.env is not
available. The preload script now explicitly whitelists the env vars the
renderer needs and exposes them as window.env via contextBridge.
constants.ts reads from window.env in the renderer and falls back to
process.env for the inso CLI and main process.
jackkav and others added 12 commits June 1, 2026 10:30
- key-value-editor and templating/utils now import encryptSecretValue/
  decryptSecretValue from vault-crypto instead of vault, so the new
  implementation is actually exercised
- Replace window.crypto with globalThis.crypto so vault-crypto works in
  Web Workers (self.crypto) and Node.js/inso (globalThis.crypto)
Removes the dynamic import of httpsnippet from the renderer so it is
no longer bundled there. Prepares for nodeIntegration: false, as
httpsnippet's core requires Node built-ins (querystring, url) that
won't be available in the renderer without nodeIntegration.
Replace key={Date.now()} with a useEffect that calls editorRef.current.setValue(snippet)
whenever snippet changes, keeping the editor mounted. Also apply prettier fixes from quick-check.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The screenshot assertion inherited the full 25s expect timeout and caused
the 'can send requests' test to exceed its 60s CI budget. The three
structural assertions above it (toBeVisible, blob src, chrome-extension
frame poll) already provide sufficient smoke-level PDF coverage.
Prevents a race condition where the dialog closes and the test navigates
before the updateEnvironmentFetcher NeDB write completes. Playwright's
click() waits for aria-disabled to clear, so the test blocks until idle.
- vault-crypto: replace forge-in-renderer with IPC bridge (main process
  retains forge; renderer calls window.main.vault.{en,de}cryptSecretValue)
- mime.ts: expand lookup table to 48 entries (webp, wasm, mp4, docx, xlsx,
  fonts, audio/video, etc.) and fix remaining mime-types import in send route
- response-viewer: move charset alias map to module level; normalise iconv-lite
  alias names (utf8, latin1, win1252, …) to WHATWG labels for TextDecoder
- auth.clear-vault-key: fix typo "all you local" → "all your local"
Extract pure data constants (blockedPropertyRules, blockedRootRules,
maskRules) and their interfaces (ASTRule, ThreatRule) into a new
script-security-rules.ts with no Node.js imports.

script-security-policy.ts now re-exports from that module and retains
only interceptorRules, which needs requireInterceptor. scripting-settings.tsx
imports directly from script-security-rules so the renderer does not
transitively pull in require-interceptor.
@jackkav jackkav force-pushed the pr/safe-utilities-cleanup branch from 88fc536 to 805fcc4 Compare June 1, 2026 08:30
@jackkav jackkav enabled auto-merge (squash) June 1, 2026 08:36
@jackkav jackkav changed the title Remove heavyweight third-party imports: mime-types, tough-cookie, @grpc/grpc-js, node-forge Remove heavyweight third-party imports: tough-cookie, @grpc/grpc-js, node-forge Jun 1, 2026
@jackkav jackkav changed the title Remove heavyweight third-party imports: tough-cookie, @grpc/grpc-js, node-forge Remove all third-party npm package imports from the renderer bundle Jun 1, 2026
@jackkav jackkav merged commit f36e1a8 into develop Jun 1, 2026
27 of 28 checks passed
@jackkav jackkav deleted the pr/safe-utilities-cleanup branch June 1, 2026 08:44
jackkav added a commit that referenced this pull request Jun 1, 2026
- vault-crypto: replace forge-in-renderer with IPC bridge (main process
  retains forge; renderer calls window.main.vault.{en,de}cryptSecretValue)
- mime.ts: expand lookup table to 48 entries (webp, wasm, mp4, docx, xlsx,
  fonts, audio/video, etc.) and fix remaining mime-types import in send route
- response-viewer: move charset alias map to module level; normalise iconv-lite
  alias names (utf8, latin1, win1252, …) to WHATWG labels for TextDecoder
- auth.clear-vault-key: fix typo "all you local" → "all your local"
jackkav added a commit that referenced this pull request Jun 2, 2026
- vault-crypto: replace forge-in-renderer with IPC bridge (main process
  retains forge; renderer calls window.main.vault.{en,de}cryptSecretValue)
- mime.ts: expand lookup table to 48 entries (webp, wasm, mp4, docx, xlsx,
  fonts, audio/video, etc.) and fix remaining mime-types import in send route
- response-viewer: move charset alias map to module level; normalise iconv-lite
  alias names (utf8, latin1, win1252, …) to WHATWG labels for TextDecoder
- auth.clear-vault-key: fix typo "all you local" → "all your local"
jackkav added a commit that referenced this pull request Jun 3, 2026
- vault-crypto: replace forge-in-renderer with IPC bridge (main process
  retains forge; renderer calls window.main.vault.{en,de}cryptSecretValue)
- mime.ts: expand lookup table to 48 entries (webp, wasm, mp4, docx, xlsx,
  fonts, audio/video, etc.) and fix remaining mime-types import in send route
- response-viewer: move charset alias map to module level; normalise iconv-lite
  alias names (utf8, latin1, win1252, …) to WHATWG labels for TextDecoder
- auth.clear-vault-key: fix typo "all you local" → "all your local"
jackkav added a commit that referenced this pull request Jun 3, 2026
- vault-crypto: replace forge-in-renderer with IPC bridge (main process
  retains forge; renderer calls window.main.vault.{en,de}cryptSecretValue)
- mime.ts: expand lookup table to 48 entries (webp, wasm, mp4, docx, xlsx,
  fonts, audio/video, etc.) and fix remaining mime-types import in send route
- response-viewer: move charset alias map to module level; normalise iconv-lite
  alias names (utf8, latin1, win1252, …) to WHATWG labels for TextDecoder
- auth.clear-vault-key: fix typo "all you local" → "all your local"
jackkav added a commit that referenced this pull request Jun 4, 2026
- vault-crypto: replace forge-in-renderer with IPC bridge (main process
  retains forge; renderer calls window.main.vault.{en,de}cryptSecretValue)
- mime.ts: expand lookup table to 48 entries (webp, wasm, mp4, docx, xlsx,
  fonts, audio/video, etc.) and fix remaining mime-types import in send route
- response-viewer: move charset alias map to module level; normalise iconv-lite
  alias names (utf8, latin1, win1252, …) to WHATWG labels for TextDecoder
- auth.clear-vault-key: fix typo "all you local" → "all your local"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants