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

refactor: error boundary #8

Merged
merged 3 commits into from
Dec 19, 2023
Merged

Conversation

MaxFrank13
Copy link
Member

This refactors the ErrorBoundary for the Plugin wrapper component to use the ErrorBoundary from frontend-platform. This ErrorBoundary component takes in an optional prop for a custom ErrorFallback component.

There is also the loadingFallback optional prop that is passed to pluginProps of the PluginSlot component. Some wording around the loadingFallback has been changed to make it more clear what the intention of this particular fallback component is so as not to confuse it will the ErrorFallback component.

Comment on lines +20 to +26
const ErrorFallbackDefault = ({ intl }) => (
<div>
<h2>
{intl.formatMessage(messages.unexpectedError)}
</h2>
</div>
);
Copy link
Member Author

@MaxFrank13 MaxFrank13 Dec 18, 2023

Choose a reason for hiding this comment

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

I changed the errorFallBackProp to ErrorFallbackComponent. It is now capitalized to signify that it is a React component. The reason why I wanted to make this clear is because the <ErrorBoundary /> component from frontend-platform wouldn't render anything unless it was provided as a React Component (ie. <ErrorFallback />). It was picking up on the prop but wasn't rendering it to the page unless it was provided this way.

@@ -71,7 +71,7 @@ const PluginContainerIframe = ({
scrolling={scrolling}
referrerPolicy="origin" // The sent referrer will be limited to the origin of the referring page: its scheme, host, and port.
className={classNames(
'border border-0',
'border border-0 w-100',
Copy link
Member Author

Choose a reason for hiding this comment

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

This sets the width: 100%; CSS rule that enables the iframe to stretch its width to available space. The width is currently being set (I believe) by the useElementSize() hook which sets the width to a fixed number determined by the elements that are wrapped by the plugin

Comment on lines +37 to +42
const defaultLoadingFallback = (
<div className={classNames(pluginProps.className, 'd-flex justify-content-center align-items-center')}>
<Spinner animation="border" screenReaderText={intl.formatMessage(messages.loading)} />
</div>
);
if (fallback !== undefined) {
finalFallback = fallback;
}
const finalLoadingFallback = loadingFallback !== undefined ? loadingFallback : defaultLoadingFallback;
Copy link
Member Author

@MaxFrank13 MaxFrank13 Dec 18, 2023

Choose a reason for hiding this comment

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

This is now loadingFallback to better show what it is used for. This fallback will be rendered the page while the PLUGIN_READY value is false. The PLUGIN_READY event is fired when the Plugin component mounts. This event will never fire if there is no Plugin being wrapped by the PluginSlot . And thus the spinner would remain on the screen with no indication to the viewer.

This is important to note when creating Plugin — perhaps a PluginWrapper component should be encouraged? Similar to what is used in the test files? This ensures that alerts, or any other fallback components for the Plugin, are wrapped and thus will fire the "ready" event which will clear the loading spinner and render whatever fallback is intended. Happy to elaborate more on this

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (74ac86b) 75.00% compared to head (93084fe) 75.19%.
Report is 2 commits behind head on master.

Files Patch % Lines
src/plugins/PluginSlot.jsx 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master       #8      +/-   ##
==========================================
+ Coverage   75.00%   75.19%   +0.19%     
==========================================
  Files          10       10              
  Lines         132      129       -3     
  Branches       19       19              
==========================================
- Hits           99       97       -2     
+ Misses         31       30       -1     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MaxFrank13 MaxFrank13 merged commit 9064049 into master Dec 19, 2023
5 of 6 checks passed
@MaxFrank13 MaxFrank13 deleted the mfrank/refactor-error-boundary branch January 23, 2024 20:46
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.

2 participants