Skip to content

Commit

Permalink
revert no ssr source change
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Oct 19, 2019
1 parent 7115cc2 commit bd5acfe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
26 changes: 1 addition & 25 deletions packages/material-ui/src/NoSsr/NoSsr.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const useEnhancedEffect =
function NoSsr(props) {
const { children, defer = false, fallback = null } = props;
const [mountedState, setMountedState] = React.useState(false);
const mounted = React.useRef();

useEnhancedEffect(() => {
if (!defer) {
Expand All @@ -29,31 +28,8 @@ function NoSsr(props) {

React.useEffect(() => {
if (defer) {
mounted.current = true;
// Wondering why we use two RAFs? Check this video out:
// https://www.youtube.com/watch?v=cCOL7MC4Pl0
//
// The useEffect() method is called after the DOM nodes are inserted.
// The UI might not have rendering the changes. We request a frame.
requestAnimationFrame(() => {
// The browser should be about to render the DOM nodes
// that React committed at this point.
// We don't want to interrupt. Let's wait the next frame.
requestAnimationFrame(() => {
// The UI is up-to-date at this point.
// We can continue rendering the children.
if (mounted.current) {
setMountedState(true);
}
});
});

return () => {
mounted.current = false;
};
setMountedState(true);
}

return undefined;
}, [defer]);

// We need the Fragment here to force react-docgen to recognise NoSsr as a component.
Expand Down
9 changes: 2 additions & 7 deletions packages/material-ui/src/NoSsr/NoSsr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,13 @@ describe('<NoSsr />', () => {
});

describe('prop: defer', () => {
it('should defer the rendering', done => {
it('should defer the rendering', () => {
const wrapper = mount(
<NoSsr defer>
<span id="client-only">Hello</span>
</NoSsr>,
);
assert.strictEqual(wrapper.find('#client-only').exists(), false);
setTimeout(() => {
wrapper.update();
assert.strictEqual(wrapper.find('#client-only').exists(), true);
done();
}, 300);
assert.strictEqual(wrapper.find('#client-only').exists(), true);
});
});
});

0 comments on commit bd5acfe

Please sign in to comment.