Menu

Do not treat image complete as a successful decode result
📰

Do not treat image complete as a successful decode result

DEV Community: html·David Miller·14 days ago
#oG1qKSXg
#devto2#devto#dev#complete#true
Reading 0:00
15s threshold

HTMLImageElement.complete can be true for a broken image. It can also be true when the element has no source, so it cannot establish that an image loaded successfully.

For an image-processing step, handle the operation you actually need. If the next step requires decoding, await decode() and handle rejection before replacing the preview. Keep the selected job identifier available when your application allows another file to be chosen during that wait.

The following is an illustrative boundary around an existing image element:

async function requireDecodedImage ( image ) { await image . decode (); return image ; }

Enter fullscreen mode

Exit fullscreen mode

Handle rejection in the caller. A rejected promise should leave the previous preview intact when that is the intended interface behavior. Do not label an export ready merely because an earlier complete check returned true.

Keep load or decode status separate from the later canvas drawing and export result.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.