[docs] Fix layout jump on first mistake #35215
Merged
+16
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
React runner has a cache to render an element in the case of an exception. However, if the very first update he's given is broken, a layout shift breaks the DX. I got annoyed by this a couple of times. It's frequent for the first edit to make the code broken.
Before
Screen.Recording.2022-11-21.at.01.14.18.mov
https://mui.com/material-ui/react-alert/#basic-alerts
Instead, what we can do is render the correct version as soon as the developer starts to interact with the demo. The other added benefit is that it makes it easier to spot broken react runner runtimes.
After
Screen.Recording.2022-11-21.at.01.16.23.mov
https://deploy-preview-35215--material-ui.netlify.app/material-ui/react-alert/#basic-alerts
I almost wonder if it would make sense to scroll-lock the editor. Even with this change, it's frequent to make changes that are disorienting when focusing on the code editor. The downside of a scroll lock would be that when we actually want to focus on the demo, it might feel strange to see it expand from the top, and not the bottom.