Git Product home page Git Product logo

Comments (7)

fantasticsoul avatar fantasticsoul commented on August 21, 2024

你在run函数加一个log 函数看看 渲染触发原因,然后再报告给我看下log 记录

run( {}, {
  middlewares:[(stateInfo, next)=>{
    console.warn(stateInfo);
    next();
  }],
});

from helux.

fantasticsoul avatar fantasticsoul commented on August 21, 2024

对了,最新的react提供了 React.StrictMode 组件来包装根组件,然后触发双调用来故意触发两次渲染,以便排除一些渲染过程中书写了副作用代码导致的bug,该特性仅在开发模式有效,生产模式会关闭,更多信息可参考:

http://react.html.cn/docs/strict-mode.html
https://frontarm.com/daishi-kato/use-ref-in-concurrent-mode/

你可以写个普通组件测试一下,就明白原因了

btw,提几个优化点😀

1 源头处也支持触发lazy,这样就可以不用再reducer里写lazy了
https://github.com/henryzp/concent-test-demo/blob/master/src/pages/tihai/index.tsx

changeTab: (key: string) => ctx.mr.changeTab(key),
// 可改为
changeTab: (key: string) => ctx.mr.changeTab(key, {lazy:true}),

2 可以写个setState,替代无逻辑的reducer函数

export function changeActiveTabKey(key: string) {
  return {
    activeTabKey: key,
  };
}

export function setModalVisible(visible: boolean) {
  return {
    modalVisible: visible,
  };
}

// 可改为
export function setState(partialState){
  return partialState;
}

from helux.

henryzp avatar henryzp commented on August 21, 2024

image

from helux.

henryzp avatar henryzp commented on August 21, 2024

@fantasticsoul ,hi,你的建议很棒,非常感谢。。

不过上面说的问题,还是没有排查出来原因。。。你方便代码clone下来,跑一下么?我是把公司的那个项目给最小化精简了,然后用了umi3的脚手架,启动是没有问题的

from helux.

fantasticsoul avatar fantasticsoul commented on August 21, 2024

我测了下,umi没有使用StrictMode,你提到的问题原因已找到
concent本身是精确通知到位了的,这里的两次渲染时react组件自上而下株连式的渲染导致的,你只需要包装React.memo即可

export default React.memo(() => {
  console.log('2222222222');
  // your code
});

from helux.

henryzp avatar henryzp commented on August 21, 2024

@fantasticsoul ,没有明白react组件自上而下株连式的渲染。。能详细说一下么?或者给个资料也行。。。

from helux.

fantasticsoul avatar fantasticsoul commented on August 21, 2024

@fantasticsoul ,没有明白react组件自上而下株连式的渲染。。能详细说一下么?或者给个资料也行。。。

React的渲染时自顶向下的

<A><B><C/></B></A>

如果A触发渲染了,没有优化机制的话默认会把他所有的孩子跟着一起渲染,所以才让你包一个memo

from helux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.