Giter Site home page Giter Site logo

Comments (3)

jaywcjlove avatar jaywcjlove commented on June 18, 2024

const caches = cachesRef.current;
let root = caches.get(id);
// 存在则不需要重新创建直接进行render操作
if (root) {
root.render(render);
} else {
// @ts-ignore
root = _ReactDOM.createRoot(document.getElementById(id)!);
root.render(render);
// 缓存,解决控制台报 ReactDOMClient.createRoot 问题
caches.set(id, root);
}
cachesRef.current = caches;

上面示例是找到 dom 重新 render, 当你切换示例预览的时候,导致 ReactDOMRoot root 节点还是以前的,如下代码切换的时候 dom 节点被更新了

{!noPreview && !onlyEdit && (
<div
className={[
`${prefixCls}-demo`,
!bgWhite ? `${prefixCls}-demo-bgPlaid` : null,
errorMessage ? `${prefixCls}-demo-error` : null,
]
.filter(Boolean)
.join(' ')
.trim()}
style={{
flex: 1,
...(width === 1 ? { width: '100%' } : {}),
}}
>
<ErrorMessage message={errorMessage} />
<div
className={[`${prefixCls}-demo-source`, errorMessage ? 'error' : null].filter(Boolean).join(' ').trim()}
id={playerId.current}
/>
</div>
)}

@LonelyFellas

from react-code-preview.

LonelyFellas avatar LonelyFellas commented on June 18, 2024

@jaywcjlove 我知道。所以这块怎么改呢。
是不是应该在监听onPreview为false属性中把这个dom移除掉呢

from react-code-preview.

jaywcjlove avatar jaywcjlove commented on June 18, 2024

@LonelyFellas 有一个解决方法,对预览的展示隐藏通过 css 去控制节点就不会被移除

from react-code-preview.

Related Issues (11)

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.