Skip to content

Spike: Support marking expensive loaders and skip unnecessary revalidation by actions submit #10064

Draft
cwangsmv wants to merge 2 commits into
developfrom
spike/add-scopes-to-loader-action
Draft

Spike: Support marking expensive loaders and skip unnecessary revalidation by actions submit #10064
cwangsmv wants to merge 2 commits into
developfrom
spike/add-scopes-to-loader-action

Conversation

@cwangsmv

@cwangsmv cwangsmv commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Changes:

Add shouldRevalidate with an enforced scope registry:

  • Loaders export shouldRevalidate which revalidates only when the submission's declared scopes intersect the loader's scope.
  • A reserved scope field is injected into the submission body

Design doc: https://konghq.atlassian.net/wiki/spaces/~7120200ecfc756d7d24b19aacb30d7ea8bf917/pages/5620924446/Decoupling+Loaders+from+Action+Revalidation

INS-2735

Copilot AI review requested due to automatic review settings June 11, 2026 07:18
@cwangsmv cwangsmv marked this pull request as draft June 11, 2026 07:18
@github-actions

Copy link
Copy Markdown

✅ Circular References Report

Generated at: 2026-06-11T07:21:53.049Z
Status: ✅ NO CHANGE

Summary

Metric Base (develop) PR Change
Total Circular References 9 9 0 (0.00%)
Click to view all circular references in PR (9)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia/src/main/prompt-bridge.ts -> insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.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/src/common/render.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 (9)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia/src/main/prompt-bridge.ts -> insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.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/src/common/render.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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 spikes scoped loader revalidation for the Insomnia React Router data routes, by injecting a reserved “revalidate scopes” field into action submissions and adding shouldRevalidate implementations to key loaders to skip unnecessary revalidation.

Changes:

  • Add scoped revalidation helpers (createShouldRevalidateByScopes, addScopeField) in utils/router.ts.
  • Introduce shouldRevalidate exports on root/organization/project/workspace/request routes keyed off submission scopes.
  • Update multiple action submitters to include the reserved scopes field; trim some loader-returned data (e.g. root no longer returns workspaceCount, workspace loader drops mock server/api spec lookups).

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
packages/insomnia/src/utils/router.ts Adds scope extraction + shouldRevalidate factory + scope injection helper.
packages/insomnia/src/ui/components/settings/import-export.tsx Stops relying on root workspaceCount, fetches count client-side.
packages/insomnia/src/ui/components/modals/workspace-settings-modal.tsx Removes mockServer prop and loads it lazily via services.
packages/insomnia/src/ui/components/dropdowns/workspace-dropdown.tsx Stops passing activeMockServer into workspace settings modal.
packages/insomnia/src/routes/settings.update.tsx Injects root revalidate scope into settings update submission.
packages/insomnia/src/routes/organization.tsx Adds scoped shouldRevalidate + (debug) loader logging.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.tsx Adds scoped shouldRevalidate + (debug) loader logging.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.tsx Adds scoped shouldRevalidate, trims loader payload + (debug) loader logging.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.environment.set-active.tsx Adds scope field to submission for workspace-level env changes.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.environment.set-active-global.tsx Adds scope field to global env submission (FormData path).
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId.tsx Adds scoped shouldRevalidate + (debug) loader logging.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId.send.tsx Injects request scope into send action submission.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId.response.delete.tsx Injects request scope into response delete submission (JSON).
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId.response.delete-all.tsx Injects request scope, but request encoding is inconsistent.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId.connect.tsx Injects request scope into connect submission.
packages/insomnia/src/routes/import.scan.tsx Injects empty scope list into import scan submission (FormData).
packages/insomnia/src/routes/cloud-credentials.create.tsx Injects root scope into create cloud credential submission.
packages/insomnia/src/routes/cloud-credentials.$cloudCredentialId.update.ts Injects root scope into update cloud credential submission.
packages/insomnia/src/routes/cloud-credentials.$cloudCredentialId.delete.ts Injects root scope into delete cloud credential submission.
packages/insomnia/src/routes/auth.validate-vault-key.tsx Injects root scope into validate vault key submission.
packages/insomnia/src/routes/auth.update-vault-salt.tsx Injects root scope into vault salt update submission.
packages/insomnia/src/routes/auth.reset-vault-key.tsx Injects root scope into reset vault key submission.
packages/insomnia/src/routes/auth.logout.tsx Injects root scope into logout submission (JSON).
packages/insomnia/src/routes/auth.login.tsx Injects root scope into login submission.
packages/insomnia/src/routes/auth.create-vault-key.tsx Injects root scope into create vault key submission.
packages/insomnia/src/routes/auth.clear-vault-key.tsx Injects root scope into clear vault key submission.
packages/insomnia/src/routes/auth.authorize.tsx Injects root scope into authorize submission (JSON).
packages/insomnia/src/root.tsx Adds scoped shouldRevalidate, trims loader payload + (debug) loader logging.
Comments suppressed due to low confidence (1)

packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId.response.delete-all.tsx:57

  • useRequestResponseDeleteAllActionFetcher now submits a JSON string but does not set encType: 'application/json'. Depending on the underlying fetcher.submit behavior, this can lead to incorrect request encoding and (more importantly for this PR) the scope field may not be available to shouldRevalidate in the expected json/text shape.
      return submit(
        JSON.stringify(
          addScopeField({
            scopes: ['request'],
            data: {},
          }),
        ),
        {
          action: url,
          method: 'POST',
        },
      );

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +230 to +238
if (formData && formData.has(SCOPE_TO_REVALIDATE_FIELD)) {
const scopesJsonStr = formData.get(SCOPE_TO_REVALIDATE_FIELD);
if (typeof scopesJsonStr === 'string' && isValidJSONString(scopesJsonStr)) {
const scopes = JSON.parse(scopesJsonStr);
if (Array.isArray(scopes)) {
return scopes as submitRevalidateDataScope[];
}
}
}
Comment on lines +240 to +242
if (json && typeof json === 'object' && SCOPE_TO_REVALIDATE_FIELD in json) {
return json[SCOPE_TO_REVALIDATE_FIELD] as submitRevalidateDataScope[];
}
Comment on lines +244 to +255
// JSON-encoded object
if (typeof text === 'string') {
try {
const parsed = JSON.parse(text);
if (typeof parsed === 'object' && SCOPE_TO_REVALIDATE_FIELD in parsed) {
return parsed[SCOPE_TO_REVALIDATE_FIELD] as submitRevalidateDataScope[];
}
} catch {
// Ignore JSON parse errors
}
}

// organization matches to organization.tsx for new global organization, user and current plan data (by default cached in local storage).
// project matches to organization.$organizationId.project.$projectId.tsx for all projects and its child workspace data
// workspace matches to organization.$organizationId.project.$projectId.workspace.$workspaceId.tsx for current workspace data(including meta) and its child data (environment, certificates, api spec, mock server, requests).
// request matches to organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId.tsx for request data (request, request meat, responses, request versions, mock server and routers).
Comment on lines 42 to 44
export async function clientLoader(_args: Route.ClientLoaderArgs) {
console.log(`[loader] organization`);
const { id, accountId } = await services.userSession.get();
Comment on lines 52 to 56
globalBaseEnvironments: (Environment & { workspaceName: string })[];
globalSubEnvironments: Environment[];
activeApiSpec: ApiSpec | null;
activeMockServer?: MockServer | null;
// activeApiSpec: ApiSpec | null;
// activeMockServer?: MockServer | null;
clientCertificates: ClientCertificate[];
Comment on lines 89 to 93
export async function clientLoader({ params }: Route.ClientLoaderArgs) {
console.log(
`[loader] organization.$organizationId.project.$projectId.workspace.$workspaceId.debug.request.$requestId`,
);
const { organizationId, projectId, requestId, workspaceId } = params;
Comment on lines 215 to 217
export async function clientLoader(_args: Route.ClientLoaderArgs) {
console.log(`[loader] root`);
const settings = await services.settings.get();
Comment on lines +663 to +666
const [workspaceCount, setWorkspaceCount] = useState(0);
useEffect(() => {
services.workspace.count().then(setWorkspaceCount);
}, []);
Comment on lines +57 to +66
useEffect(() => {
async function loadMockServer() {
if (models.workspace.isMockServer(workspace)) {
const mockServer = await services.mockServer.getByParentId(workspace._id);
mockServer && setMockServer(mockServer);
}
}

loadMockServer();
}, [workspace]);
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