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

Handle "empty" render() calls in noInline mode #151

Closed
wagerfield opened this issue Jun 14, 2019 · 1 comment
Closed

Handle "empty" render() calls in noInline mode #151

wagerfield opened this issue Jun 14, 2019 · 1 comment

Comments

@wagerfield
Copy link

When noInline mode is enabled and you call render with no arguments, React throws the error: https://reactjs.org/docs/error-decoder.html/?invariant=152&args[]=n

This can be seen on the React Live demo site if you scroll to the last example and delete the contents of the render call.

You get "An unexpected error has occurred." printed to the screen and there's no going back. You have to refresh the page to remedy this error.

It would be better if React live gracefully caught this error and printed it to LiveError in the same way that it does when the code is set to an empty string in "normal/inline" mode.

@wagerfield
Copy link
Author

For the time being I'm using transformCode to replace empty render calls with render(null)

const transformCode = (code) => {
  return code.replace(/render\(\s*\)/, "render(null)")
}

...but I think an error should still be thrown that's caught by LiveError

sofiapoh added a commit that referenced this issue Jul 15, 2019
Safely catch calls with empty render. Fixes #151
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

No branches or pull requests

1 participant