-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Live editor render twice times on page first mount #2986
Comments
Hi, That seems right, but this only happens on initial mount (hydration), not on navigation. It is due to a key that was added on the Playground: <Playground
key={isClient} Added in commit: refactor(v2): add @theme-init alias to give access to initial components (#2464) @lex111 do you remember why this was needed? |
If someone want to explain how to implement useMount by react hook. e.g. author of react-use. People will ask “why mount trigger two times” |
I will work on this issue |
Well I've been inspecting this, and after an hour of hopeless digging, I even got to the point where I omitted almost every prop fed to component. I was doing something like: const PlaygroundTest = memo((props) => {
console.log(props)
return <Playground {...props} />
}, (a, b) => {
console.log(a, b)
return false;
})
withLiveEditor = ((Component) => {
const WrappedComponent = (props) => {
// const {isClient} = useDocusaurusContext();
// const prismTheme = usePrismTheme();
console.log(props.live)
if (props.live) {
return (
<PlaygroundTest
// key={isClient}
scope={ReactLiveScope}
// theme={prismTheme}
// {...props}
/>
);
}
return <Component {...props} />;
};
return WrappedComponent;
}); to just test Any idea? |
@9oelM I think this is due to a similar key being on the doc:
I don't know exactly why we need this key here, it is here for a long time, but I'd be happy to remove it if it does not produce any weird side-effect |
I tried that too but it didn't work.. :( |
Seems like some other issue other than the key.. hmm |
actually, i will try again |
same issue |
🐛 Bug Report
Live editor render component twice times
Have you read the Contributing Guidelines on issues?
yes
To Reproduce
Expected behavior
log 'mount' one time
Actual Behavior
Your Environment
Reproducible Demo
(Paste the link to an example repo, including a
siteConfig.js
, and exact instructions to reproduce the issue.)The text was updated successfully, but these errors were encountered: