-
-
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
useLogo hook does not update on theme change #2646
Comments
We have not documented this hook, so it is not intended to be used by end-users.
|
Awesome. Thanks for looking into this. After putting that into the test case unfortunately the behavior is the same. import React from 'react';
import Layout from '@theme/Layout';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useLogo from '@theme/hooks/useLogo';
function LogoTest() {
const {isClient} = useDocusaurusContext();
const {logoImageUrl} = useLogo();
return (
<Layout title="LogoTest">
<img key={isClient} src={logoImageUrl} />
</Layout>
);
}
export default LogoTest; |
Indeed it is, even |
I'm still building up my mental model of this project, but in case it's of relevance pulling |
After some investigation, I found the reason. First, you should not use
In a page, you might have something like import React from 'react';
import Layout from '@theme/Layout';
function Page() {
return (
<Layout title="Foo" description="bar">
Baz
</Layout>
);
}
export default Page; If you try to import React from 'react';
import Layout from '@theme/Layout';
function Page() {
// oops, use the ThemeProvider without being its child.
const logo = useLogo();
return (
<Layout title="Foo" description="bar">
Baz
</Layout>
);
}
export default Page; A workaround is to move the content of the page to another component: import React from 'react';
import Layout from '@theme/Layout';
function Content() {
const logo = useLogo();
return logo;
}
function Page() {
return (
<Layout title="Foo" description="bar">
<Content />
</Layout>
);
}
export default Page; |
Since we removed the |
Try to fix the bug caused by theme context. See facebook/docusaurus#2646
🐛 Bug Report
When using the useLogo hook provided by theme-classic in a custom page, the associated attributes do not update following a chance between dark/light themes.
Have you read the Contributing Guidelines on issues?
👍
To Reproduce
Ensure both
navbar.logo.src
andnavbar.logo.srcDark
are set in the config.Build + load in browser.
Toggle theme light/dark state.
Expected behavior
src
attribute should change betweensrc
andsrcDark
values.Actual Behavior
src
remains on original value.Your Environment
Reproducible Demo
See above.
The text was updated successfully, but these errors were encountered: