Match-id-fe48008aa3fb3a1a23cb5b9e7ca48150426b4875

This commit is contained in:
* 2022-07-14 16:49:49 +08:00 committed by *
commit f15cd59bc7
5 changed files with 80 additions and 2 deletions

View File

@ -199,6 +199,10 @@ export function calcStartUpdateVNode(treeRoot: VNode) {
for (let i = 1; i < startNodePath.length; i++) {
const pathIndex = Number(startNodePath[i]);
node = getChildByIndex(node, pathIndex)!;
// 路径错误时,回退到从根更新
if (node == null) {
return treeRoot;
}
}
return node;

View File

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

View File

@ -0,0 +1,45 @@
import * as Horizon from '@cloudsop/horizon/index.ts';
import { getLogUtils } from '../jest/testUtils';
describe('ForwardRef', () => {
const LogUtils = getLogUtils();
it('ForwardRef包裹的函数组件应该正常触发effect', () => {
function App(props, ref) {
Horizon.useEffect(() => {
LogUtils.log('effect');
return () => {
LogUtils.log('effect remove');
};
});
return <button ref={ref}></button>;
}
const Wrapper = Horizon.forwardRef(App);
Horizon.act(() => {
Horizon.render(<Wrapper />, container);
});
expect(LogUtils.getAndClear()).toEqual(['effect']);
Horizon.act(() => {
Horizon.render(<Wrapper />, container);
});
expect(LogUtils.getAndClear()).toEqual(['effect remove', 'effect']);
});
it('memo组件包裹的类组件', () => {
class Component extends Horizon.Component {
render() {
return <button>123</button>;
}
}
const Wrapper = Horizon.memo(Component);
Horizon.act(() => {
Horizon.render(<Wrapper />, container);
});
Horizon.act(() => {
Horizon.render(<Wrapper />, container);
});
});
});

View File

@ -184,4 +184,30 @@ describe('LazyComponent Test', () => {
container.querySelector('button').click();
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();
});
});

View File

@ -23,7 +23,8 @@ if (!fs.existsSync(outDir)) {
const outputResolve = (...p) => path.resolve(outDir, ...p);
function genConfig(mode) {
const sourcemap = mode === 'development' ? 'inline' : false;
const isDev = mode === 'development';
const sourcemap = isDev ? 'inline' : false;
return {
input: path.resolve(libDir, 'index.ts'),
output: [
@ -53,7 +54,8 @@ function genConfig(mode) {
replace({
values: {
'process.env.NODE_ENV': `"${mode}"`,
isDev: 'true',
isDev: isDev.toString(),
isTest: false,
__VERSION__: `"${horizonVersion}"`,
},
preventAssignment: true,