Skip to content

Conversation

Mister-Hope
Copy link
Member

No description provided.

@Mister-Hope
Copy link
Member Author

Since the new default theme is using useData, I made a similar refactor on the old default theme.

It seems that the only benefit of the change is to reduce multiple imports and calls for developers in source code.

While the disadvantage is increasing size. Bundlers can not minify object keys, so all variable names will be left in the final output code.

After this PR, the size of the final production grows a little bit, and it can be even more if plugins and tool packages are following this change.

Honestly, since multiple imports in plugins are not common, I think we should not prefer useClientData in plugins, but for theme, the advantages and disadvantages seem kind of equal to me.

@pengzhanbo

@coveralls
Copy link

coveralls commented Feb 18, 2025

Pull Request Test Coverage Report for Build 13453957010

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 59.58%

Totals Coverage Status
Change from base Build 13453742318: 0.0%
Covered Lines: 1351
Relevant Lines: 2048

💛 - Coveralls

@pengzhanbo
Copy link
Member

After compression, the destructuring syntax is optimized during the process. It will be transformed into:

before:

const { theme, frontmatter } = useData()

after:

const {theme:a,frontmatter:b}=e()

The impact on the build size is minimal, but it will significantly enhance the development experience.

@Mister-Hope
Copy link
Member Author

Mister-Hope commented Feb 19, 2025

This PR is using the original long key

const {themeData:a,pageFrontmatter:b}=e()

so the new result is definitely longer than

const a=b();const c=d();

To avoid disadvantages, we need to shorten the key. But I think it's a bit weird for downstream ecosystem to do this while clientData in core is using longer ones.

Keys like pageFrontmatter siteLocaleData pageComponent can be shortened to frontmatter siteLocale component

@Mister-Hope Mister-Hope merged commit f144db1 into main Feb 21, 2025
34 checks passed
@Mister-Hope Mister-Hope deleted the clientData branch February 21, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants