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

Show nicer error if pdf fails to load #3184

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions static/app-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,8 @@
"Default action when clicking a playlist.": "Default action when clicking a playlist.",
"Default playlist action": "Default playlist action",
"Optionally the email change can be requested using \"Submit Feedback\" button below.": "Optionally the email change can be requested using \"Submit Feedback\" button below.",
"Failed to load": "Failed to load",
"This file failed to load. Some browser extension may be blocking it. If the issue persists, please reach out to [email protected]": "This file failed to load. Some browser extension may be blocking it. If the issue persists, please reach out to [email protected]",

"--end--": "--end--"
}
27 changes: 25 additions & 2 deletions ui/component/IframeReact/view.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import React from 'react';
import Card from 'component/common/card';

type Props = {
fullHeight: boolean,
Expand All @@ -10,11 +11,20 @@ type Props = {
export default function I18nMessage(props: Props) {
const { src, title } = props;

// const iframeRef = useRef();
const [failedToLoadSrc, setFailedToLoadSrc] = React.useState(false);
// const iframeRef = React.useRef();

// const [iframeHeight, setIframeHeight] = useState('80vh');

function onLoad() {
const checkIfSrcCanBeLoaded = async () => {
const response = await fetch(src);
if (response.status !== 200) {
setFailedToLoadSrc(true);
}
};
checkIfSrcCanBeLoaded();

/*

iframe domain restrictions prevent naive design :-(
Expand All @@ -30,6 +40,19 @@ export default function I18nMessage(props: Props) {
return (
// style={{height: iframeHeight}}
// ref={iframeRef}
<iframe src={src} title={title} onLoad={onLoad} sandbox={!IS_WEB} />
!failedToLoadSrc ? (
<iframe src={src} title={title} onLoad={onLoad} sandbox={!IS_WEB} />
) : (
<Card
title={__('Failed to load')}
subtitle={
<p>
{__(
'This file failed to load. Some browser extension may be blocking it. If the issue persists, please reach out to [email protected]'
)}
</p>
}
/>
)
);
}
Loading