Skip to content

Share one image-loading helper instead of local copies #132

Closed

Description

@vycdev

Image loading is wrapped in a promise in many separate places, and the copies behave differently:

  • decodeImage in src/App.tsx (added in Report unreadable image imports instead of failing silently #124) resolves null on error or when the image has zero width or height.
  • loadImage in src/hooks/usePrintableFeatureSimulation.ts rejects on error.
  • Inline new Image() promises in src/hooks/useQuantize.ts, src/hooks/useSwatches.ts, src/hooks/useAppHandlers.ts, src/hooks/useBuildWarning.ts, src/components/DeditherPanel.tsx, src/components/CanvasPreview.tsx and src/components/ThreeDView.tsx.

Because each copy handles errors its own way, fixes such as the zero-size guard from #124 only reach some callers.

Proposal: add one shared helper that loads an image from a URL with a single, documented failure behavior, and switch the copies above to it where their needs match. Leave callers alone when they really need different handling. AGENTS.md keeps src/lib React-free and puts browser concerns in hooks and components, so choose a location that fits that rule. This should not change behavior. The existing unit and e2e tests should pass unchanged.

Activity

  1. vycdev commented on Nov 7, 2026

    @vycdev
    OwnerAuthor

    Fixed by #141 (merged into develop).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions