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

[docs] Live demos v2 #34870

Merged
merged 3 commits into from Nov 7, 2022
Merged

[docs] Live demos v2 #34870

merged 3 commits into from Nov 7, 2022

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Oct 23, 2022

This is a continuation of #34454 (comment). The first commit is from the initial PR, the second commit is what I could make as a step forwards. I have tried to fix all the bugs but I'm stuck on point 6. I might not have the time to carry it further.

  1. ✅ 1 render in dev mode, 2 renders in prod for performance
  2. https://deploy-preview-34870--material-ui.netlify.app/versions
  3. https://deploy-preview-34870--material-ui.netlify.app/material-ui/material-icons/?selected=AcUnit
  4. https://deploy-preview-34870--material-ui.netlify.app/joy-ui/getting-started/templates/
  5. https://deploy-preview-34870--material-ui.netlify.app/material-ui/getting-started/templates/
  6. https://deploy-preview-34870--material-ui.netlify.app/material-ui/react-drawer/#swipeable-edge
  7. https://deploy-preview-34870--material-ui.netlify.app/material-ui/react-box/#the-sx-prop

Performance-wise, it seems that these changes reduce the regression: https://www.webpagetest.org/video/compare.php?tests=221106_BiDcE6_7GV,221106_AiDcGG_7EA,221106_BiDcTA_7GW

Screenshot 2022-11-06 at 19 27 15


Problem solved

@nihgwu For 6. we need to pass a prop/argument to the code that is executed. This demo https://mui.com/material-ui/react-drawer/#swipeable-edge runs inside an iframe, we normally pass it the window of the iframe as an argument for the demo:

export default function SwipeableEdgeDrawer(props: Props) {
const { window } = props;

I have tried this:

const { element, error } = useRunner({
code,
scope,
});
React.useEffect(() => {
onError(error);
}, [error, onError]);
// TODO:
// if (Object.keys(forwardProps).length > 0) {
// console.log('forwardProps', element);
// return React.cloneElement(element, forwardProps);

but there is an intermediary element in react runner that prevents cloneElement to forward the window. What would you advise? The only alternative I can think of is to create a new demo option to disable live edits for some of the demos (it's already done by default when hideToolbar is used).

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Oct 23, 2022
@mui-bot
Copy link

mui-bot commented Oct 23, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-34870--material-ui.netlify.app/

No bundle size changes

Generated by 🚫 dangerJS against 6e049cd

@nihgwu

This comment was marked as resolved.

docs/src/modules/components/ReactRunner.tsx Outdated Show resolved Hide resolved
docs/src/modules/components/Demo.js Outdated Show resolved Hide resolved
@oliviertassinari

This comment was marked as resolved.

@nihgwu

This comment was marked as resolved.

@nihgwu

This comment was marked as resolved.

@oliviertassinari

This comment was marked as resolved.

@nihgwu

This comment was marked as resolved.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 30, 2022
oliviertassinari added a commit to oliviertassinari/material-ui that referenced this pull request Oct 30, 2022
oliviertassinari added a commit to oliviertassinari/material-ui that referenced this pull request Oct 30, 2022
@oliviertassinari oliviertassinari force-pushed the restore-live-edit branch 2 times, most recently from eddedb2 to a5be41f Compare October 30, 2022 17:26
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 30, 2022
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 31, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 6, 2022
@oliviertassinari oliviertassinari marked this pull request as ready for review November 6, 2022 17:36
@oliviertassinari oliviertassinari force-pushed the restore-live-edit branch 2 times, most recently from 27aa204 to 847e582 Compare November 6, 2022 17:46
@oliviertassinari
Copy link
Member Author

I did another iteration, I can't spot any opportunities for further improvement. Open for reviews/open to be improved on

throw new Error(
[
'A demo tries to access process.x in ReactRunner. This is not supported.',
'If you do not need to show the source, you can set "hideToolbar": true to solve the issue.',
Copy link
Contributor

Choose a reason for hiding this comment

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

disableLiveEdit?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that hiding the toolbar is more relevant in this context. The developers should probably not be able to open it on codesandbox too if process is accessed. disableLiveEdit would work but would miss more improvement opportunities.

const sandboxProps = iframe ? { name, ...other } : {};

const t = useTranslate();

// `childrenProp` needs to be a child of `Sandbox` since the iframe implementation rely on `cloneElement`.
const children = <Sandbox {...sandboxProps}>{childrenProp}</Sandbox>;

return (
<DemoErrorBoundary name={name} onResetDemoClick={onResetDemoClick} t={t}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually there is ErrorBoundary in react-runner, I left it as it is for minimal change

Copy link
Member

@bharatkashyap bharatkashyap left a comment

Choose a reason for hiding this comment

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

LGTM!

@hbjORbj hbjORbj merged commit 0a29e3c into mui:master Nov 7, 2022
@oliviertassinari oliviertassinari deleted the restore-live-edit branch November 7, 2022 16:17
@oliviertassinari
Copy link
Member Author

oliviertassinari commented Nov 8, 2022

I saw these issues with this implementation:

I will fix it this weekend, It should be pretty quick. I have something working for 2, and 1 might be about triggering the live env when the editor is focused.

@bharatkashyap
Copy link
Member

bharatkashyap commented Nov 9, 2022

I saw issues with this implementation:

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Nov 30, 2022

A few more opportunities for improvements that we saw:

Screenshot 2022-11-15 at 23 12 13

  • 8. Some undo/redo strange behaviors.

It seems that we are pretty much done :). I will take care of 7. 8 is more of the realm of react-simple-code-editor.

feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation new feature New feature or request scope: docs-infra Specific to the docs-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants