Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback image for broken images #2434

Merged
merged 2 commits into from
Apr 22, 2024
Merged

Add fallback image for broken images #2434

merged 2 commits into from
Apr 22, 2024

Conversation

SleeplessOne1917
Copy link
Member

Closes #2433.

This is what is looks like with the fallback image:
Screenshot_20240420_140939


function handleImgLoadError(i: PictrsImage) {
i.setState({
src: `${getStaticDir()}/assets/images/broken-image-fallback.png`,
Copy link
Member

Choose a reason for hiding this comment

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

Try this solution to see if it works.

<img src="foo.jpg" onerror="this.src='NEW_SRC_LOC>

Then we could avoid having to have to create a src state variable, and hooks, just to handle the error case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

<img src="foo.jpg" onerror="this.src='NEW_SRC_LOC>

I tried something similar at some point. Worked fine in dev. But in prod the CSP complained about inline-scripts.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, in that case this is good then.

@dessalines dessalines enabled auto-merge (squash) April 22, 2024 15:52
@dessalines dessalines merged commit c1b8946 into main Apr 22, 2024
2 checks passed
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.

Fallback image for when images are broken
3 participants