render.tsx (storybook-6.5.11) | : | render.tsx (storybook-6.5.12) | ||
---|---|---|---|---|
skipping to change at line 42 | skipping to change at line 42 | |||
} | } | |||
return <Component {...args} />; | return <Component {...args} />; | |||
}; | }; | |||
const WithCallback: FC<{ callback: () => void; children: ReactElement }> = ({ | const WithCallback: FC<{ callback: () => void; children: ReactElement }> = ({ | |||
callback, | callback, | |||
children, | children, | |||
}) => { | }) => { | |||
// See https://github.com/reactwg/react-18/discussions/5#discussioncomment-227 6079 | // See https://github.com/reactwg/react-18/discussions/5#discussioncomment-227 6079 | |||
const once = useRef(false); | const once = useRef<() => void>(); | |||
useLayoutEffect(() => { | useLayoutEffect(() => { | |||
if (once.current) return; | if (once.current === callback) return; | |||
once.current = true; | once.current = callback; | |||
callback(); | callback(); | |||
}, [callback]); | }, [callback]); | |||
return children; | return children; | |||
}; | }; | |||
const renderElement = async (node: ReactElement, el: Element) => { | const renderElement = async (node: ReactElement, el: Element) => { | |||
// Create Root Element conditionally for new React 18 Root Api | // Create Root Element conditionally for new React 18 Root Api | |||
const root = await getReactRoot(el); | const root = await getReactRoot(el); | |||
return new Promise((resolve) => { | return new Promise((resolve) => { | |||
if (root) { | if (root) { | |||
root.render( | root.render(<WithCallback callback={() => resolve(null)}>{node}</WithCallb | |||
<WithCallback key={Math.random()} callback={() => resolve(null)}> | ack>); | |||
{node} | ||||
</WithCallback> | ||||
); | ||||
} else { | } else { | |||
ReactDOM.render(node, el, () => resolve(null)); | ReactDOM.render(node, el, () => resolve(null)); | |||
} | } | |||
}); | }); | |||
}; | }; | |||
const canUseNewReactRootApi = | const canUseNewReactRootApi = | |||
reactDomVersion && (reactDomVersion.startsWith('18') || reactDomVersion.starts With('0.0.0')); | reactDomVersion && (reactDomVersion.startsWith('18') || reactDomVersion.starts With('0.0.0')); | |||
const shouldUseNewRootApi = FRAMEWORK_OPTIONS?.legacyRootApi !== true; | const shouldUseNewRootApi = FRAMEWORK_OPTIONS?.legacyRootApi !== true; | |||
End of changes. 3 change blocks. | ||||
8 lines changed or deleted | 5 lines changed or added |