Skip to content

[website] Fix layout shift on homepage #46461

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 61 additions & 48 deletions docs/src/modules/components/AppSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,57 +328,70 @@ export default function AppSearch(props) {
<SearchButton onRef={searchButtonRef} onClick={onOpen} {...props} />
{isOpen &&
ReactDOM.createPortal(
<DocSearchModal
initialQuery={initialQuery}
appId="TZGZ85B9TB"
apiKey="8177dfb3e2be72b241ffb8c5abafa899"
indexName="material-ui"
searchParameters={{
facetFilters: ['version:master', facetFilterLanguage],
optionalFilters,
attributesToRetrieve: [
// Copied from https://github.com/algolia/docsearch/blob/ce0c865cd8767e961ce3088b3155fc982d4c2e2e/packages/docsearch-react/src/DocSearchModal.tsx#L231
'hierarchy.lvl0',
'hierarchy.lvl1',
'hierarchy.lvl2',
'hierarchy.lvl3',
'hierarchy.lvl4',
'hierarchy.lvl5',
'content',
'type',
'url',
// Extra
'productId',
'productCategoryId',
],
analyticsTags: [facetFilterLanguage, `product:${pageContext.productId}`],
hitsPerPage: 40,
<div
ref={() => {
const html = document.querySelector('html');
if (html) {
html.style.overflow = 'hidden';
Copy link
Contributor Author

@sai6855 sai6855 Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternate way is remove margin-right:15px added by Algolia

 const body = document.querySelector('body');
     if (body) {
        body.style.marginRight = '';
  }

}

return () => {
html.style.overflow = 'auto';
};
}}
placeholder={`${t('algoliaSearch')}`}
transformItems={(items) => {
return items.map((item) => {
// `url` contains the domain
// but we want to link to the current domain e.g. deploy-preview-1--material-ui.netlify.app
const parseUrl = document.createElement('a');
parseUrl.href = item.url;
>
<DocSearchModal
initialQuery={initialQuery}
appId="TZGZ85B9TB"
apiKey="8177dfb3e2be72b241ffb8c5abafa899"
indexName="material-ui"
searchParameters={{
facetFilters: ['version:master', facetFilterLanguage],
optionalFilters,
attributesToRetrieve: [
// Copied from https://github.com/algolia/docsearch/blob/ce0c865cd8767e961ce3088b3155fc982d4c2e2e/packages/docsearch-react/src/DocSearchModal.tsx#L231
'hierarchy.lvl0',
'hierarchy.lvl1',
'hierarchy.lvl2',
'hierarchy.lvl3',
'hierarchy.lvl4',
'hierarchy.lvl5',
'content',
'type',
'url',
// Extra
'productId',
'productCategoryId',
],
analyticsTags: [facetFilterLanguage, `product:${pageContext.productId}`],
hitsPerPage: 40,
}}
placeholder={`${t('algoliaSearch')}`}
transformItems={(items) => {
return items.map((item) => {
// `url` contains the domain
// but we want to link to the current domain e.g. deploy-preview-1--material-ui.netlify.app
const parseUrl = document.createElement('a');
parseUrl.href = item.url;

const { canonicalAs, canonicalPathname } = pathnameToLanguage(
`${parseUrl.pathname}${parseUrl.hash}`,
);
const { canonicalAs, canonicalPathname } = pathnameToLanguage(
`${parseUrl.pathname}${parseUrl.hash}`,
);

return {
...item,
pathname: canonicalPathname,
as: canonicalAs,
userLanguage,
};
});
}}
hitComponent={DocSearchHit}
initialScrollY={typeof window !== 'undefined' ? window.scrollY : undefined}
onClose={onClose}
navigator={keyboardNavigator}
/>,
return {
...item,
pathname: canonicalPathname,
as: canonicalAs,
userLanguage,
};
});
}}
hitComponent={DocSearchHit}
initialScrollY={typeof window !== 'undefined' ? window.scrollY : undefined}
onClose={onClose}
navigator={keyboardNavigator}
/>
</div>,
document.body,
)}
<GlobalStyles
Expand Down