Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Building off of my other PR: Passing error to children #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

krishnaglick
Copy link

I didn't want to redo all the footwork here: #8
So that should be looked at and merged first.

Using div means this affects the dom. This could have unintended consequences. Replacing it with React.Fragment (<> shorthand) removes that issue.
@Wishez
Copy link

Wishez commented Jun 19, 2020

Those are good improvments for this package:) Thank you:3

@@ -64,7 +64,7 @@ export function _render (self, ProvideContext) {
const __html = renderToStaticMarkup(elementWithProviders)
return <div dangerouslySetInnerHTML={{__html}} />
} catch (e) {
return <div>{self.props.fallBack()}</div>
return <>{self.props.fallBack()}</>
Copy link

Choose a reason for hiding this comment

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

I think, the Fragmet syntax is excess here:) fallBack'll return some jsx elements already

Copy link

Choose a reason for hiding this comment

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

If the server's fallback gets an exception's error in arguments, it would be cool too;)

...
catch (error) {
  return self.props.fallBack({ error })
}

Choose a reason for hiding this comment

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

This is going to be a problem when React tries to hydrate the DOM. If the DOM structure doesn't match what would normally be rendered, then it can result in zombie elements which do not get re-rendered. The fallback content isn't going to be the same as whatever we expected to render, but removing that div even with no fallback will be something that hydrate handles badly.

const { error, errorInfo, hasError } = this.state;
if (hasError) {
return this.props.fallBack({ error, errorInfo });
} else {
Copy link

Choose a reason for hiding this comment

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

You can write conditions after "else" without "else". Possible, it'll be read better that way;)

const { fallBack, children } = this.props
if (hasError) return fallBack({ error, errorInfo })

return typeof children === 'function' ? children({ error, errorInfo }) : children

@zvictor
Copy link

zvictor commented Jun 29, 2020

@krishnaglick could you publish a release on your own github repo? I would like to start using your version instead 🙂

@krishnaglick
Copy link
Author

This didn't end up working exactly how I wanted, and I haven't had time to revisit it.
I did publish here: https://www.npmjs.com/package/async-react-ssr-error-boundary

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants