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
Fix flash when switching top level sections #23
Fix flash when switching top level sections #23
Conversation
🏖 This preview environment has been fully cleaned up. See you next time! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this isn't done yet — let me know when ready for review (you can add WIP to PR title)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok yes this makes sense. However I'm confused why dynamic
is even being used at all. I realized that currently docs are not being SSRd ever. if you disable JS, it's a white page with is crap for SEO.
So we need to fix that, but we can do it in another pr
const getBestGlobMatch = (globs, path) => { | ||
const match = globs | ||
.filter(p => minimatch(path, p)) | ||
.sort((m1, m2) => { | ||
const d1 = fastLevenshtein.get(m1, path) | ||
const d2 = fastLevenshtein.get(m2, path) | ||
return d1 < d2 ? -1 : 1 | ||
})?.[0] | ||
|
||
if (match === undefined && globs.includes('**/*')) { | ||
return '**/*' | ||
} | ||
return match | ||
} | ||
|
||
const getTemplateId = (pathname) => { | ||
const templateMappings = (motifConfig.templates) || {} | ||
const path = pathname === '/' ? '' : pathname.replace(/^\//, '') | ||
const matchingGlob = getBestGlobMatch(Object.keys(templateMappings), path) | ||
if (matchingGlob !== undefined && matchingGlob in templateMappings) { | ||
return templateMappings[matchingGlob] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should all be moved out of the component
motif-docs/pages/_app.tsx
Outdated
} | ||
const Template = dynamic<{children: React.ReactNode, meta: any, path: string, filename: string, files: {}}>(() => | ||
import('@templates/documentation.mdx').then(mod => (mod as any).Template), | ||
{ ssr: false }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed?
Import the main documentation template at the top level of the
_app.tsx
file instead of thegetTemplate()
function.