Match-id-cf9d94e9056eee2f779cb69c820ebeccdd606f55

This commit is contained in:
* 2022-07-14 16:43:48 +08:00 committed by *
parent 02c598d858
commit 95506416dc
2 changed files with 27 additions and 0 deletions

View File

@ -61,6 +61,7 @@ function captureLazyComponent(
if (lazyRender) { if (lazyRender) {
if (lazyVNodeTag === MemoComponent) { if (lazyVNodeTag === MemoComponent) {
// Memo要特殊处理 // Memo要特殊处理
processing.effectList = null;
const memoVNodeProps = mergeDefaultProps(Component.type, lazyVNodeProps); // 需要整合defaultProps const memoVNodeProps = mergeDefaultProps(Component.type, lazyVNodeProps); // 需要整合defaultProps
return lazyRender(processing, Component, memoVNodeProps, shouldUpdate); return lazyRender(processing, Component, memoVNodeProps, shouldUpdate);
} else { } else {

View File

@ -184,4 +184,30 @@ describe('LazyComponent Test', () => {
container.querySelector('button').click(); container.querySelector('button').click();
expect(container.textContent).toBe('Error: num is 2'); expect(container.textContent).toBe('Error: num is 2');
}); });
it('#24 配合memo', async () => {
const fnComp = () => {
return <h1>horizon</h1>;
};
const LazyApp = Horizon.lazy(() => ({
then(cb) {
cb({ default: Horizon.memo(() => fnComp, false) });
},
}));
expect(() => {
Horizon.render(
<Horizon.Suspense fallback={<div>Loading...</div>}>
<LazyApp text="Lazy" />
</Horizon.Suspense>,
container
);
Horizon.render(
<Horizon.Suspense fallback={<div>Loading...</div>}>
<LazyApp text="Lazy" />
</Horizon.Suspense>,
container
);
}).not.toThrow();
});
}); });