Move restricted template rendering to plugin window#9943
Open
jackkav wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR completes “blocker #2” of the nodeIntegration migration by moving restricted Nunjucks template rendering (including template-tag extensions) out of the main renderer’s Web Worker and into the hidden plugin window, accessed via a new plugins.renderTemplate bridge method.
Changes:
- Add
plugins.renderTemplateto the plugin bridge and route restricted template rendering through the plugin window. - Introduce render-context serialization/rehydration and error (de)serialization across the plugin-window boundary.
- Remove legacy renderer Web Worker templating entrypoints and update related docs/tests.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/insomnia/src/ui/worker/templating-worker.ts | Removes the renderer-owned templating Web Worker. |
| packages/insomnia/src/ui/worker/templating-handler.ts | Switches template rendering to plugins.renderTemplate and adds context/error normalization helpers. |
| packages/insomnia/src/templating/worker.ts | Deletes the old worker-side Nunjucks pipeline implementation. |
| packages/insomnia/src/templating/base-extension-worker.ts | Updates templating import path (worker-side extension helper). |
| packages/insomnia/src/plugins/renderer-bridge.ts | Exposes renderTemplate on the renderer bridge API. |
| packages/insomnia/src/plugins/invoke-method.ts | Adds renderTemplate handler and rehydrates serialized render context in the plugin window; reload now also resets templating cache. |
| packages/insomnia/src/plugins/bridge-types.ts | Adds IPC types for serialized render context and RenderTemplateArgs. |
| packages/insomnia/src/plugins/tests/invoke-method.test.ts | Adds test coverage for render-context rehydration. |
| packages/insomnia/src/main/plugin-window.ts | Adds plugins.renderTemplate IPC handler; improves error normalization from plugin window results. |
| packages/insomnia/src/entry.preload.ts | Exposes window.main.plugins.renderTemplate from preload via invokeWithNormalizedError. |
| packages/insomnia/src/entry.plugin-window.ts | Serializes errors across the plugin-window → main boundary with richer metadata. |
| packages/insomnia/src/entry.plugin-window-preload.ts | Adds minimal window.main APIs needed by plugin-window execution. |
| packages/insomnia/PLUGIN_SYSTEM_POC.md | Updates blocker notes to reflect the new plugin-window templating architecture. |
| packages/insomnia/NODE_INTEGRATION_MIGRATION_PR_PLAN.md | Refreshes the migration plan to reflect current codebase status. |
| AGENTS.md | Updates contributor guidance formatting and worktree setup notes. |
Comments suppressed due to low confidence (1)
packages/insomnia/src/ui/worker/templating-handler.ts:12
- serializeRenderContext() currently spreads the full BaseRenderContext into the IPC payload. BaseRenderContext includes function properties (getMeta/getKeysContext/etc), and Electron IPC (structured clone) cannot serialize functions, so this call will fail at runtime when invoking plugins.renderTemplate. Build the serialized context by omitting all function-valued properties (or explicitly picking only data keys) before sending it over IPC.
function serializeRenderContext(context: RenderInputType['context']): RenderTemplateArgs['context'] {
return {
...context,
serializedFunctions: {
requestId: context.getMeta().requestId,
workspaceId: context.getMeta().workspaceId,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+24
to
33
| function normalizeRenderError(error: unknown, input: string, context: RenderTemplateArgs['context']) { | ||
| const source = error instanceof Error ? error : new Error(String(error)); | ||
| const renderError = new RenderError(source.message); | ||
| const errorDetails = source as RenderError; | ||
|
|
||
| renderError.path = errorDetails.path || ''; | ||
| renderError.location = errorDetails.location; | ||
| renderError.type = errorDetails.type || 'render'; | ||
| renderError.reason = errorDetails.reason; | ||
|
|
| @@ -1,5 +1,5 @@ | |||
| import type { ResponsePatch } from '../main/network/libcurl-promise'; | |||
| import type { RenderedRequest } from '../templating/types'; | |||
| import type { BaseRenderContext, RenderedRequest,RenderPurpose } from '../templating/types'; | |||
Comment on lines
+55
to
+72
| ## Repository Structure | ||
|
|
||
| `packages/` | ||
| `insomnia/` ← Main Electron app | ||
| `src/` | ||
| `common/` ← Shared utils, settings types | ||
| `models/` ← Data model definitions | ||
| `insomnia-data/` ← Model defaults, init(), NeDB db implementation, business logic | ||
| `routes/` ← React Router files (clientLoader/clientAction) | ||
| `ui/` ← React components, hooks, `insomnia-fetch.ts` | ||
| `main/` ← Electron IPC handlers, `preload.ts` | ||
| `account/` ← Auth, session, encryption | ||
| `sync/` ← Git/VCS sync | ||
| `network/` ← Request execution engine | ||
| `templating/` ← Nunjucks rendering (Web Worker) | ||
| `insomnia-api/` ← Cloud API client | ||
| `insomnia-inso/` ← CLI tool | ||
| `insomnia-testing/` ← Test framework | ||
| `insomnia/` ← Main Electron app | ||
| `src/` | ||
| `common/` ← Shared utils, settings types | ||
| `models/` ← Data model definitions | ||
| `insomnia-data/` ← Model defaults, init(), NeDB db implementation, business logic | ||
| `routes/` ← React Router files (clientLoader/clientAction) | ||
| `ui/` ← React components, hooks, `insomnia-fetch.ts` | ||
| `main/` ← Electron IPC handlers, `preload.ts` | ||
| `account/` ← Auth, session, encryption | ||
| `sync/` ← Git/VCS sync | ||
| `network/` ← Request execution engine | ||
| `templating/` ← Nunjucks rendering (Web Worker) | ||
| `insomnia-api/` ← Cloud API client | ||
| `insomnia-inso/` ← CLI tool | ||
| `insomnia-testing/` ← Test framework |
Comment on lines
+50
to
+56
| export async function renderInWorker({ | ||
| input, | ||
| context, | ||
| path, | ||
| ignoreUndefinedEnvVariable, | ||
| }: RenderInputType): Promise<string> { | ||
| const serializedContext = serializeRenderContext(context); |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c315ee2 to
754997c
Compare
- Fix serializeRenderContext to filter out function-valued properties
before spreading context over IPC (structured clone cannot serialize
functions, causing "An object could not be cloned" errors in CI)
- Add safe fallbacks in normalizeRenderError: location defaults to
{line:1,column:1} and reason defaults to 'error' to prevent crashes
in RequestRenderErrorModal when fields are absent after IPC crossing
- Rename renderInWorker -> renderViaPluginBridge to reflect that
rendering now routes through the plugin window, not a Web Worker
- Fix missing space after comma in bridge-types.ts import
- Restore indented tree formatting in AGENTS.md Repository Structure section
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
plugins.renderTemplateIPC methodWhy
This finishes blocker 2 by ensuring template tag extensions no longer execute inside a renderer-owned web worker. Restricted template rendering now runs alongside the rest of the plugin surfaces in the plugin window.