Skip to content

Fix potential double form submission in signup tracking #20

@leogdion

Description

@leogdion

Issue

The form submission logic in index.ts:20-32 has both a callback AND a setTimeout, which could result in duplicate submissions if the callback executes quickly.

Current code:

plausible.trackEvent("signup", {
  callback: () => {
    formElement.submit();  // Submit #1
  },
  props,
});
setTimeout(() => {
  formElement.submit();    // Submit #2 (after 500ms)
}, 500);

Impact

Users might receive duplicate emails or create duplicate records in the system.

Recommendation

Remove the redundant setTimeout or add a flag to prevent double submission:

let submitted = false;
plausible.trackEvent("signup", {
  callback: () => {
    if (!submitted) {
      submitted = true;
      formElement.submit();
    }
  },
  props,
});
setTimeout(() => {
  if (!submitted) {
    submitted = true;
    formElement.submit();
  }
}, 500);

This ensures the form is only submitted once, either when the tracking callback fires or after 500ms timeout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions