Skip to content

Multi-Page & Multi-Output Conversions Trigger Infinite Polling Loop and Disable Action Buttons #718

Closed

Description

@codeCraft-Ritik
  • Affected Files:
    • src/pages/results.tsx (Lines 31, 33, 39, 43, 54)
    • public/results.js (Lines 8–22)
    • src/converters/main.ts (Lines 200–222)
  • Severity: High (UI Deadlock & Unbounded Polling DoS)
  • Type: Functional / Performance / Race / UI Defect

Description & Root Cause

ConvertX natively supports conversions where a single input yields multiple output files (e.g. converting a multi-page PDF, DJVU, or animated GIF into individual page images). In src/converters/main.ts lines 200–222, handleConvert detects numbered output files (${stem}-0.png, ${stem}-1.png, etc.) and inserts a record into file_names for each generated file. Once finished, it updates the job status to 'completed' in the jobs table.

However, in src/pages/convert.tsx line 81:

db.query("UPDATE jobs SET num_files = ?1, status = 'pending' WHERE id = ?2").run(
  fileNames.length,
  jobId.value,
);

job.num_files stores the number of input files (e.g., 1 for one uploaded PDF).

When rendering the results page in src/pages/results.tsx:

// src/pages/results.tsx, lines 31-44
<button
  type="submit"
  style={files.length !== job.num_files ? "pointer-events: none;" : ""}
  class="flex btn-secondary flex-row gap-2 text-contrast"
  {...(files.length !== job.num_files ? { disabled: true, "aria-busy": "true" } : "")}
>
  <DeleteIcon /> <p>Delete</p>
</button>
<a
  style={files.length !== job.num_files ? "pointer-events: none;" : ""}
  href={`${WEBROOT}/archive/${job.id}`}
  download={`converted_files_${job.id}.tar`}
  class="flex btn-primary flex-row gap-2 text-contrast"
  {...(files.length !== job.num_files ? { disabled: true, "aria-busy": "true" } : "")}
>
  <DownloadIcon /> <p>Tar</p>
</a>
<progress
  max={job.num_files}
  {...(files.length === job.num_files ? { value: files.length } : "")}
/>

When a single input produces 3 output images:

  • files.length is 3.
  • job.num_files is 1.
  • files.length !== job.num_files (3 !== 1) evaluates to true.

Consequences:

  1. The Delete and Tar buttons are permanently disabled with pointer-events: none.
  2. The <progress> element never receives a value attribute and remains in an indeterminate loading state.
  3. In public/results.js:
// public/results.js, lines 8-19
if (progressElem.value !== progressElem.max) {
  fetch(`${webroot}/progress/${jobId}`, {
    method: "POST",
  })
    .then((res) => res.text())
    .then((html) => {
      main.innerHTML = html;
    })
    .catch((err) => console.log(err));

  setTimeout(refreshData, 1000);
}

An indeterminate <progress> element in HTML DOM has progressElem.value === 0. Because 0 !== 1 is always true, setTimeout(refreshData, 1000) executes indefinitely. The client repeatedly sends POST /progress/:jobId every second forever, causing continuous DOM re-renders and unnecessary server CPU/network load.

Steps to Reproduce

  1. Upload a multi-page PDF (e.g. 3 pages) and choose conversion to png.
  2. The converter finishes successfully, creates doc-0.png, doc-1.png, doc-2.png, and marks the job status as 'completed' in the database.
  3. Open the results page /results/:jobId.
  4. Observe the UI: the progress bar loops continuously, the Tar button and Delete button are disabled and cannot be clicked.
  5. Inspect the browser Network tab: POST /progress/:jobId requests are fired every 1000ms indefinitely.

Expected Behavior

When conversion finishes (or when job.status === 'completed'), the progress bar should show completion, polling should stop, and the Tar and Delete buttons should be clickable.

Actual Behavior

The UI is stuck in a permanent polling loop; the buttons remain disabled forever.

Suggested Fix

Base the completion condition on job.status === "completed" or files.length >= job.num_files rather than strict equality:

--- a/src/pages/results.tsx
+++ b/src/pages/results.tsx
@@ -22,6 +22,7 @@ function ResultsArticle({
   outputPath: string;
 }) {
+  const isCompleted = job.status === "completed" || files.length >= job.num_files;
   return (
     <article class="article">
       <div class="mb-4 flex items-center justify-between">
@@ -30,19 +31,19 @@ function ResultsArticle({
           <form action={`${WEBROOT}/delete/${job.id}`} method="POST">
             <button
               type="submit"
-              style={files.length !== job.num_files ? "pointer-events: none;" : ""}
+              style={!isCompleted ? "pointer-events: none;" : ""}
               class="flex btn-secondary flex-row gap-2 text-contrast"
-              {...(files.length !== job.num_files ? { disabled: true, "aria-busy": "true" } : "")}
+              {...(!isCompleted ? { disabled: true, "aria-busy": "true" } : "")}
             >
               <DeleteIcon /> <p>Delete</p>
             </button>
           </form>
           <a
-            style={files.length !== job.num_files ? "pointer-events: none;" : ""}
+            style={!isCompleted ? "pointer-events: none;" : ""}
             href={`${WEBROOT}/archive/${job.id}`}
             download={`converted_files_${job.id}.tar`}
             class="flex btn-primary flex-row gap-2 text-contrast"
-            {...(files.length !== job.num_files ? { disabled: true, "aria-busy": "true" } : "")}
+            {...(!isCompleted ? { disabled: true, "aria-busy": "true" } : "")}
           >
             <DownloadIcon /> <p>Tar</p>
           </a>
@@ -52,8 +53,8 @@ function ResultsArticle({
         </div>
       </div>
       <progress
-        max={job.num_files}
-        {...(files.length === job.num_files ? { value: files.length } : "")}
+        max={Math.max(job.num_files, files.length)}
+        {...(isCompleted ? { value: Math.max(job.num_files, files.length) } : {})}
         class={`

Activity

  1. added
    bug
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions