Skip to content

CP-13553: Refactor Docuseal PDF page loading and previews#65

Merged
spaulsandhu merged 8 commits into
mainfrom
CP-13553
May 12, 2026
Merged

CP-13553: Refactor Docuseal PDF page loading and previews#65
spaulsandhu merged 8 commits into
mainfrom
CP-13553

Conversation

@spaulsandhu
Copy link
Copy Markdown
Member

Overview

This includes a bunch of tweaks to the underlying infrastructure in the way Docuseal serves up Documents in the Editor and Preview pages.

Gone is the lazy loading mechanic and 15 page cap to the preview. The lazy loading mechanic was BUGGY AF due to our iFrame situation and the 15 page cap was just kind of nonsensical to begin with. Please look at each commit as each one of them has context that makes it clear why and what the changes are.

Video overview: https://www.loom.com/share/26defd1e361f41699614516a220bb8ac

spaulsandhu and others added 5 commits May 11, 2026 15:34
DocuSeal previously rendered only the first 15 pages of a PDF synchronously
at upload time and then lazily generated pages 16+ on demand when the editor
or submitter view actually requested them. The on-demand path lived in
PreviewDocumentPageController and had a long history of bugs — tempfile
races, intermittent failures, filename-extension mismatches between writer
and reader — especially when DocuSeal is iframed into ATS.

This removes the 15-page cap (MAX_NUMBER_OF_PAGES_PROCESSED) and the lazy
on-demand controller entirely. Every page now renders during the upload
request. Larger PDFs take a few extra seconds at upload, but every page is
guaranteed to exist by the time the editor opens, so the whole on-demand
failure surface disappears.

Also deletes two unused job classes (GeneratePreviewImagesJob and
GenerateAttachmentPreviewJob) that had no callers anywhere in the app, plus
the now-obsolete spec for the deleted generate_pdf_preview_from_file helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The template builder used to fall back to a /preview/<token>/<n>.jpg URL
for any page that wasn't already in document.preview_images, and applied
loading="lazy" to each page <img>. Both pieces only existed to paper over
the missing pages 16+ from the old upload cap.

Since the backend now renders every page at upload time, the fallback URL
is never needed. sortedPreviewImages becomes a simple map-filter over the
already-rendered images, and basePreviewUrl is unused so it's removed too.

Also drops loading="lazy" from page.vue and preview.vue. Native lazy
loading does not trigger reliably inside the ATS iframe — images would
sometimes refuse to fetch until the user scroll-spammed past them. With
every page now reachable as a direct S3 URL on initial render, the browser
can just load them up front.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mirrors the previous commit but for the Rails-rendered submit-form and
completed-submission views. Drops the page_blob_struct / lazyload_metadata
machinery that built fallback URLs pointing at the now-deleted /preview
controller, and removes loading="lazy" from the page-list <img> tags for
the same iframe-reliability reasons as the editor change.

Single-image attachment thumbnails (signatures, user-uploaded files) keep
their loading="lazy" attributes — those aren't part of a scrollable page
list and don't hit the same iframe-rendering quirk.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The old Submissions.preload_with_pages had two pieces that no longer make
sense after removing the lazy preview controller:

1. It preloaded `:blob` on the document attachments themselves. The views
   only ever accessed `document.blob` indirectly through the now-deleted
   lazy controller's `attachment.download` call. Bullet was correctly
   flagging the preload as unused.

2. It skipped preloading preview_images for documents with 200+ pages and
   relied on the views' lazy-URL fallback to fill the gap. With the
   fallback gone, large documents were rendering zero pages in the Rails
   form preview because preview_images.loaded? returned false and the
   index ended up empty.

This always preloads `preview_images_attachments: :blob` regardless of
page count, and drops both unused `:blob` preloads on the document
attachments. Also removes the now-unused PRELOAD_ALL_PAGES_AMOUNT
constants in lib/submissions.rb and lib/submitters.rb.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Does what it says on the box.
Copy link
Copy Markdown
Collaborator

@bernardodsanderson bernardodsanderson left a comment

Choose a reason for hiding this comment

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

This looks great! Just a few asks here. Another thing I was wondering is if we need/want to backfill rake task for all the forms created before this PR is live?

Comment thread app/javascript/template_builder/document.vue Outdated
Comment thread app/javascript/template_builder/document.vue Outdated
Co-authored-by: Bernardo Anderson <bern.anderson@proton.me>
Comment on lines 98 to 114
@@ -113,26 +113,13 @@ export default {
}
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is this the change you wanna make? 🤔

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Basically, delete the baseUrl

baseUrl: {
      type: String,
      required: false,
      default: ''
    },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I tried selecting the whole thing to delete it 😞

Copy link
Copy Markdown
Collaborator

@bernardodsanderson bernardodsanderson left a comment

Choose a reason for hiding this comment

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

:shipit:

@spaulsandhu spaulsandhu merged commit e69609e into main May 12, 2026
4 of 5 checks passed
@spaulsandhu spaulsandhu deleted the CP-13553 branch May 12, 2026 19:59
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