[PR #1039] [MERGED] fix: update document flow fetch logic #1336

Closed
opened 2026-02-26 19:32:50 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/documenso/documenso/pull/1039
Author: @dguyen
Created: 3/20/2024
Status: Merged
Merged: 3/26/2024
Merged by: @dguyen

Base: mainHead: fix/edit-document-data-refresh


📝 Commits (6)

  • 79d931d feat: add state to document flow
  • 63f6cde feat: update query invalidation logic
  • a05e897 Merge branch 'main' into fix/edit-document-data-refresh
  • 22e7688 fix: correct logic
  • 1166fd9 fix: optimise field inserts
  • 8d9b306 fix: use trpc primitives for data setting

📊 Changes

17 files changed (+279 additions, -81 deletions)

View changed files

📝 apps/web/src/app/(dashboard)/documents/[id]/edit-document.tsx (+93 -31)
📝 apps/web/src/app/(dashboard)/documents/[id]/edit/document-edit-page-view.tsx (+5 -24)
📝 apps/web/src/app/(signing)/sign/[token]/date-field.tsx (+3 -2)
📝 apps/web/src/app/(signing)/sign/[token]/email-field.tsx (+3 -2)
📝 apps/web/src/app/(signing)/sign/[token]/name-field.tsx (+3 -2)
📝 apps/web/src/app/(signing)/sign/[token]/signature-field.tsx (+3 -2)
📝 apps/web/src/app/(signing)/sign/[token]/text-field.tsx (+3 -2)
📝 apps/web/src/components/(dashboard)/common/command-menu.tsx (+8 -0)
packages/lib/constants/trpc.ts (+25 -0)
packages/lib/server-only/document/get-document-with-details-by-id.ts (+32 -0)
📝 packages/lib/server-only/field/set-fields-for-document.ts (+12 -4)
📝 packages/lib/server-only/recipient/set-recipients-for-document.ts (+15 -2)
📝 packages/prisma/types/document.ts (+14 -1)
📝 packages/trpc/client/index.ts (+10 -4)
📝 packages/trpc/react/index.tsx (+21 -5)
📝 packages/trpc/server/document-router/router.ts (+20 -0)
📝 packages/trpc/server/document-router/schema.ts (+9 -0)

📄 Description

Description

Fixes issues with mismatching state between document steps.

For example, editing a recipient and proceeding to the next step may not display the updated recipient. And going back will display the old recipient instead of the updated values.

This PR also improves mutation and query speeds by adding logic to bypass query invalidation.

export const trpc = createTRPCReact<AppRouter>({
  unstable_overrides: {
    useMutation: {
      async onSuccess(opts) {
        await opts.originalFn();

        // This forces mutations to wait for all the queries on the page to reload, and in
        // this case one of the queries is `searchDocument` for the command overlay, which
        // on average takes ~500ms. This means that every single mutation must wait for this.
        await opts.queryClient.invalidateQueries(); 
      },
    },
  },
});

I've added workarounds to allow us to bypass things such as batching and invalidating queries. But I think we should instead remove this and update all the mutations where a query is required for a more optimised system.

Example benchmarks

Using stg-app vs this preview there's an average 50% speed increase across mutations.

Set signer step:
Average old speed: ~1100ms
Average new speed: ~550ms

Set recipient step:
Average old speed: ~1200ms
Average new speed: ~600ms

Set fields step:
Average old speed: ~1200ms
Average new speed: ~600ms

This will resolve #470

Changes Made

  • Added ability to skip batch queries
  • Added a state to store the required document data.
  • Refetch the data between steps if/when required
  • Optimise mutations and queries

Checklist

  • I have tested these changes locally and they work as expected.
  • I have followed the project's coding style guidelines.

🔄 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/documenso/documenso/pull/1039 **Author:** [@dguyen](https://github.com/dguyen) **Created:** 3/20/2024 **Status:** ✅ Merged **Merged:** 3/26/2024 **Merged by:** [@dguyen](https://github.com/dguyen) **Base:** `main` ← **Head:** `fix/edit-document-data-refresh` --- ### 📝 Commits (6) - [`79d931d`](https://github.com/documenso/documenso/commit/79d931dc5772b699ccc607f5039f51137af5283f) feat: add state to document flow - [`63f6cde`](https://github.com/documenso/documenso/commit/63f6cde4ec1ed2fbf17335ebeedcd37ea5e7ee9e) feat: update query invalidation logic - [`a05e897`](https://github.com/documenso/documenso/commit/a05e897e12134c08ca0facbd54b91c7833ddde41) Merge branch 'main' into fix/edit-document-data-refresh - [`22e7688`](https://github.com/documenso/documenso/commit/22e768852dcd8879fb24a5d7f8ec33eee250e772) fix: correct logic - [`1166fd9`](https://github.com/documenso/documenso/commit/1166fd902aea4d6d07bca60420fc62d85402e009) fix: optimise field inserts - [`8d9b306`](https://github.com/documenso/documenso/commit/8d9b306485c1733382842bae8939494b7e32f89c) fix: use trpc primitives for data setting ### 📊 Changes **17 files changed** (+279 additions, -81 deletions) <details> <summary>View changed files</summary> 📝 `apps/web/src/app/(dashboard)/documents/[id]/edit-document.tsx` (+93 -31) 📝 `apps/web/src/app/(dashboard)/documents/[id]/edit/document-edit-page-view.tsx` (+5 -24) 📝 `apps/web/src/app/(signing)/sign/[token]/date-field.tsx` (+3 -2) 📝 `apps/web/src/app/(signing)/sign/[token]/email-field.tsx` (+3 -2) 📝 `apps/web/src/app/(signing)/sign/[token]/name-field.tsx` (+3 -2) 📝 `apps/web/src/app/(signing)/sign/[token]/signature-field.tsx` (+3 -2) 📝 `apps/web/src/app/(signing)/sign/[token]/text-field.tsx` (+3 -2) 📝 `apps/web/src/components/(dashboard)/common/command-menu.tsx` (+8 -0) ➕ `packages/lib/constants/trpc.ts` (+25 -0) ➕ `packages/lib/server-only/document/get-document-with-details-by-id.ts` (+32 -0) 📝 `packages/lib/server-only/field/set-fields-for-document.ts` (+12 -4) 📝 `packages/lib/server-only/recipient/set-recipients-for-document.ts` (+15 -2) 📝 `packages/prisma/types/document.ts` (+14 -1) 📝 `packages/trpc/client/index.ts` (+10 -4) 📝 `packages/trpc/react/index.tsx` (+21 -5) 📝 `packages/trpc/server/document-router/router.ts` (+20 -0) 📝 `packages/trpc/server/document-router/schema.ts` (+9 -0) </details> ### 📄 Description ## Description **Fixes issues with mismatching state between document steps.** For example, editing a recipient and proceeding to the next step may not display the updated recipient. And going back will display the old recipient instead of the updated values. **This PR also improves mutation and query speeds by adding logic to bypass query invalidation.** ```ts export const trpc = createTRPCReact<AppRouter>({ unstable_overrides: { useMutation: { async onSuccess(opts) { await opts.originalFn(); // This forces mutations to wait for all the queries on the page to reload, and in // this case one of the queries is `searchDocument` for the command overlay, which // on average takes ~500ms. This means that every single mutation must wait for this. await opts.queryClient.invalidateQueries(); }, }, }, }); ``` I've added workarounds to allow us to bypass things such as batching and invalidating queries. But I think we should instead remove this and update all the mutations where a query is required for a more optimised system. ## Example benchmarks Using stg-app vs this preview there's an average 50% speed increase across mutations. **Set signer step:** Average old speed: ~1100ms Average new speed: ~550ms **Set recipient step:** Average old speed: ~1200ms Average new speed: ~600ms **Set fields step:** Average old speed: ~1200ms Average new speed: ~600ms ## Related Issue This will resolve #470 ## Changes Made - Added ability to skip batch queries - Added a state to store the required document data. - Refetch the data between steps if/when required - Optimise mutations and queries ## Checklist - [X] I have tested these changes locally and they work as expected. - [X] I have followed the project's coding style guidelines. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 19:32:50 +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/documenso#1336
No description provided.