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

fix(live-codeblock): add error boundary to live code preview #8015

Merged
merged 9 commits into from
Oct 13, 2022
Merged

fix(live-codeblock): add error boundary to live code preview #8015

merged 9 commits into from
Oct 13, 2022

Conversation

rashidmya
Copy link
Contributor

@rashidmya rashidmya commented Aug 27, 2022

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

Fixes page crashing when typing undefined or {} in live editor

Test Plan

Test links

Deploy preview: https://deploy-preview-8015--docusaurus-2.netlify.app/

Related issues/PRs

fix #8009

@facebook-github-bot
Copy link
Contributor

Hi @rashidmya!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@netlify
Copy link

netlify bot commented Aug 27, 2022

[V2]

Name Link
🔨 Latest commit fd54f12
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6348307e1bd1f50009097c52
😎 Deploy Preview https://deploy-preview-8015--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Aug 27, 2022

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 58 🟢 98 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟠 88 🟢 100 🟢 100 🟢 100 🟢 90 Report

@Josh-Cena
Copy link
Collaborator

Note, we already have an error boundary component in core: https://docusaurus.io/docs/docusaurus-core#errorboundary Please just reuse this one

@rashidmya
Copy link
Contributor Author

using error boundary component in core results in this behavior inside the live editor. is that okay?

Capture

@Josh-Cena
Copy link
Collaborator

You should provide a custom fallback.

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Aug 27, 2022
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@rashidmya
Copy link
Contributor Author

Its working correctly now. any notes?

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

This does not render very nicely

CleanShot 2022-09-01 at 12 24 47@2x

Please make sure the error is displayed nicely, maybe keep the "results" header tab, and ensure there's still the padding/background?

We want the design to be consistent with other playground errors such as:

CleanShot 2022-09-01 at 12 28 46@2x

Maybe you could reuse the LiveError component? 🤷‍♂️

Note you introduce a new translation label but do not provide translations for it (and thus CI fails). You could reuse the key "theme.ErrorPageContent.tryAgain" to fix this. I can't merge if the CI fails

@rashidmya
Copy link
Contributor Author

Capture
is this better?

I had difficulty figuring out how to reuse the LiveError component

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

this looks better yes!

@rashidmya rashidmya requested review from slorber and removed request for lex111 and Josh-Cena September 7, 2022 11:30
@rashidmya
Copy link
Contributor Author

@slorber why does CI fail when I added styles for the component

@slorber slorber changed the title added error boundary to playground fix(live-codeblock): add error boundary to live code preview Oct 13, 2022
@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Oct 13, 2022
@slorber
Copy link
Collaborator

slorber commented Oct 13, 2022

@slorber why does CI fail when I added styles for the component

The CI says it: you just added an extra ! in the tryAgain button label, and we end up with 2 buttons in our theme with the same key but different labels which we should avoid.

LGTM 👍 just did minor fixes


Note I tried to do some kind of "auto try again on code change" behavior but it's complicated because it seems const {code,error} = useContext(LiveContext) does not update for some reason when code string contains error, so the auto retry is hard to trigger with an effect.

Also we still have weird annoying cases where both the live error and the error boundary crash are displayed at the same time. Tried to improve but react-live does not make it very easy unfortunately

When code change from "crash" to "react-live-error" state, both are displayed. Unless we find a way to autoretry the error boundary I think it's better to display the live error in addition (even if it's weird) rather that staying on the rough error boundary crash message:

CleanShot 2022-10-13 at 17 41 24@2x

Those are edge cases, probably not worth investing a lot of time on these atm

@slorber slorber merged commit 79b3f65 into facebook:main Oct 13, 2022
This was referenced Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undefined crashes live codeblock
4 participants