Skip to content

Move restricted template rendering to plugin window#9943

Open
jackkav wants to merge 5 commits into
Kong:developfrom
jackkav:copilot/worktree-2026-05-21T08-11-39
Open

Move restricted template rendering to plugin window#9943
jackkav wants to merge 5 commits into
Kong:developfrom
jackkav:copilot/worktree-2026-05-21T08-11-39

Conversation

@jackkav
Copy link
Copy Markdown
Contributor

@jackkav jackkav commented May 21, 2026

Summary

  • route restricted template rendering through the plugin window bridge with a new plugins.renderTemplate IPC method
  • rehydrate render context and preserve rich render error metadata across the plugin-window boundary
  • remove the obsolete renderer worker templating entrypoints and update the blocker 2 notes/tests

Why

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.

Copilot AI review requested due to automatic review settings May 21, 2026 08:27
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

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.renderTemplate to 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 thread AGENTS.md Outdated
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);
jackkav and others added 2 commits May 21, 2026 13:59
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jackkav jackkav force-pushed the copilot/worktree-2026-05-21T08-11-39 branch from c315ee2 to 754997c Compare May 21, 2026 11:59
jackkav and others added 3 commits May 21, 2026 15:11
- 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>
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.

2 participants