-
Notifications
You must be signed in to change notification settings - Fork 155
extract theme as separate package @graphprotocol/theme
#336
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
Conversation
📦 Next.js Bundle Analysis for @graphprotocol/docsThis analysis was generated by the Next.js Bundle Analysis action. 🤖 🎉 Global Bundle Size Decreased
DetailsThe global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster. Any third party scripts you have added directly to your app using the If you want further insight into what is behind the changes, give @next/bundle-analyzer a try! Six Hundred Twelve Pages Changed SizeThe following pages changed size from the code in this PR compared to its base branch:
DetailsOnly the gzipped size is provided here based on an expert tip. First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If Any third party scripts you have added directly to your app using the The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored. |
@@ -1,8 +1,8 @@ | |||
import { useI18n } from '@/i18n' | |||
import { useI18n } from '@edgeandnode/components' |
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.
There is a difference between @edgeandnode/components
's useI18n
and the local one, in terms of types. Why this change? 🤔
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 function should be generic (to accept different translations) since now useI18n
lives in packages/theme
(or maybe I should rename it packages/nextra-theme
)
A current function definition is
export const useI18n = () => _useI18n<typeof translations>()
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.
Oh, right, each package that uses the theme might have its own translatable strings... still, the theme itself will only ever refer to strings that exist within the theme, so it's almost like we'd need 3 layers of this. Oh well, I guess this works, it just doesn't provide the nice autocomplete experience. :P
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.
yeah, we lose autocomplete
|
||
export type LinkProps = Pick<NextLinkProps, 'replace' | 'scroll' | 'shallow' | 'prefetch'> & | ||
Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & { | ||
href?: NextLinkProps['href'] | ||
locale?: AppLocale |
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 remove all references to @/i18n
?
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.
If anything, I think @/i18n
should be part of the theme, and website
should import it from the theme.
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 described #336 (comment) why I removed all @/i18n
usages
// @ts-expect-error todo: fix type error | ||
const __nextra_internal__ = (globalThis as NextraInternalGlobal)[NEXTRA_INTERNAL] | ||
|
||
const internal = __nextra_internal__.context?.[router.route] | ||
const hasMDXPage = !!internal | ||
const { pageOpts = {} } = internal || {} | ||
const locale = router.asPath.split('/')[1] as Locale | ||
|
||
pageOpts.headings = useMemo(() => { | ||
if (!hasMDXPage) return [] | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return pageOpts.filePath === 'pages/[locale]/index.mdx' | ||
? [ | ||
{ | ||
id: 'network-roles', | ||
value: translate(translations, locale, 'index.networkRoles.title'), | ||
depth: 2, | ||
}, | ||
{ | ||
id: 'products', | ||
value: translate(translations, locale, 'index.products.title'), | ||
depth: 2, | ||
}, | ||
{ | ||
id: 'supported-networks', | ||
value: translate(translations, locale, 'index.supportedNetworks.title'), | ||
depth: 2, | ||
}, | ||
] | ||
: pageOpts.headings | ||
}, [hasMDXPage, pageOpts.filePath, pageOpts.headings, locale]) | ||
|
||
pageOpts.pageMap = useMemo(() => { | ||
if (!hasMDXPage) return [] | ||
const pageMap = (__nextra_internal__.pageMap as PageMapItem[]).find( | ||
(pageItem): pageItem is Folder => pageItem.kind === 'Folder' && pageItem.name === locale | ||
)!.children | ||
pageMap.find((pageItem): pageItem is MetaJsonFile => pageItem.kind === 'Meta')!.data.index = translate( | ||
translations, | ||
locale, | ||
'index.title' | ||
) | ||
return pageMap | ||
}, [__nextra_internal__.pageMap, hasMDXPage, locale]) |
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 whole thing seems pretty hacky. 😅
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.
it is hacky due [locale]/index.mdx
file if we'll refactor to en/index.mdx
, fr/index.mdx
the whole mentioned code will be a lot simplified (because normally TOC headings are parsed but here I inject these headings only for this index
page)
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.
But that page has a lot of custom styles. I'm not sure how we could convert it to Markdown that is simple enough to be read/translatable by Crowdin.
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.
custom styles can be extracted as React components but headings need to exist as raw markdown headings
---
title: My title
---
## Foo bar
<SomeSections />
### Qux
<SomeLogos />
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, good idea.
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 will create an issue for 👆, will rename theme
folder to nextra-theme
and we are ready to merge it!
The next one is Remote MDX PR!
"@edgeandnode/components": "^27.4.1", | ||
"@emotion/react": "^11.10.6", | ||
"@radix-ui/react-collapsible": "1.0.2", | ||
"@radix-ui/react-visually-hidden": "^1.0.2", | ||
"@graphprotocol/nextra-theme": "workspace:*", |
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.
Nice, I didn't know that trick.
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.
it assume to use local version
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 left comments for potential improvements, but this is great, thank you!
No description provided.