@lobehub/lobehub 2.0.0-next.337 → 2.0.0-next.339

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/.gitattributes +35 -0
  2. package/CHANGELOG.md +69 -0
  3. package/changelog/v1.json +24 -0
  4. package/locales/ar/plugin.json +12 -2
  5. package/locales/ar/providers.json +1 -0
  6. package/locales/ar/setting.json +77 -1
  7. package/locales/bg-BG/models.json +5 -10
  8. package/locales/bg-BG/plugin.json +12 -2
  9. package/locales/bg-BG/providers.json +1 -0
  10. package/locales/bg-BG/setting.json +78 -2
  11. package/locales/de-DE/models.json +51 -9
  12. package/locales/de-DE/plugin.json +12 -2
  13. package/locales/de-DE/providers.json +1 -0
  14. package/locales/de-DE/setting.json +78 -2
  15. package/locales/en-US/models.json +11 -10
  16. package/locales/en-US/plugin.json +14 -4
  17. package/locales/en-US/providers.json +1 -0
  18. package/locales/en-US/setting.json +97 -2
  19. package/locales/es-ES/plugin.json +12 -2
  20. package/locales/es-ES/providers.json +1 -0
  21. package/locales/es-ES/setting.json +78 -2
  22. package/locales/fa-IR/plugin.json +12 -2
  23. package/locales/fa-IR/providers.json +1 -0
  24. package/locales/fa-IR/setting.json +78 -2
  25. package/locales/fr-FR/plugin.json +12 -2
  26. package/locales/fr-FR/providers.json +1 -0
  27. package/locales/fr-FR/setting.json +78 -2
  28. package/locales/it-IT/plugin.json +12 -2
  29. package/locales/it-IT/providers.json +1 -0
  30. package/locales/it-IT/setting.json +78 -2
  31. package/locales/ja-JP/plugin.json +12 -2
  32. package/locales/ja-JP/providers.json +1 -0
  33. package/locales/ja-JP/setting.json +78 -2
  34. package/locales/ko-KR/plugin.json +12 -2
  35. package/locales/ko-KR/providers.json +1 -0
  36. package/locales/ko-KR/setting.json +78 -2
  37. package/locales/nl-NL/models.json +4 -9
  38. package/locales/nl-NL/plugin.json +12 -2
  39. package/locales/nl-NL/providers.json +1 -0
  40. package/locales/nl-NL/setting.json +78 -2
  41. package/locales/pl-PL/plugin.json +12 -2
  42. package/locales/pl-PL/providers.json +1 -0
  43. package/locales/pl-PL/setting.json +78 -2
  44. package/locales/pt-BR/plugin.json +12 -2
  45. package/locales/pt-BR/providers.json +1 -0
  46. package/locales/pt-BR/setting.json +78 -2
  47. package/locales/ru-RU/plugin.json +12 -2
  48. package/locales/ru-RU/providers.json +1 -0
  49. package/locales/ru-RU/setting.json +78 -2
  50. package/locales/tr-TR/plugin.json +12 -2
  51. package/locales/tr-TR/providers.json +1 -0
  52. package/locales/tr-TR/setting.json +78 -2
  53. package/locales/vi-VN/plugin.json +12 -2
  54. package/locales/vi-VN/providers.json +1 -0
  55. package/locales/vi-VN/setting.json +77 -1
  56. package/locales/zh-CN/auth.json +1 -0
  57. package/locales/zh-CN/plugin.json +12 -2
  58. package/locales/zh-CN/providers.json +1 -0
  59. package/locales/zh-CN/setting.json +97 -2
  60. package/locales/zh-TW/plugin.json +12 -2
  61. package/locales/zh-TW/providers.json +1 -0
  62. package/locales/zh-TW/setting.json +78 -2
  63. package/package.json +1 -1
  64. package/packages/agent-runtime/src/groupOrchestration/GroupOrchestrationSupervisor.ts +2 -0
  65. package/packages/agent-runtime/src/groupOrchestration/__tests__/GroupOrchestrationSupervisor.test.ts +3 -1
  66. package/packages/agent-runtime/src/groupOrchestration/types.ts +5 -0
  67. package/packages/const/src/index.ts +1 -0
  68. package/packages/const/src/klavis.ts +144 -0
  69. package/packages/const/src/lobehubSkill.ts +34 -0
  70. package/packages/const/src/recommendedSkill.ts +17 -0
  71. package/packages/model-runtime/src/core/contextBuilders/anthropic.test.ts +38 -0
  72. package/packages/model-runtime/src/core/contextBuilders/anthropic.ts +20 -1
  73. package/packages/model-runtime/src/core/contextBuilders/google.test.ts +42 -0
  74. package/packages/model-runtime/src/core/contextBuilders/google.ts +17 -0
  75. package/packages/model-runtime/src/providers/google/index.ts +14 -14
  76. package/packages/model-runtime/src/providers/moonshot/index.ts +1 -1
  77. package/packages/model-runtime/src/providers/openai/index.ts +3 -3
  78. package/packages/types/src/discover/index.ts +1 -1
  79. package/scripts/electronWorkflow/modifiers/dynamicToStatic.mts +273 -0
  80. package/scripts/electronWorkflow/modifiers/index.mts +10 -0
  81. package/scripts/electronWorkflow/modifiers/nextConfig.mts +1 -0
  82. package/scripts/electronWorkflow/modifiers/nextDynamicToStatic.mts +233 -0
  83. package/scripts/electronWorkflow/modifiers/removeSuspense.mts +124 -0
  84. package/scripts/electronWorkflow/modifiers/routes.mts +14 -2
  85. package/scripts/electronWorkflow/modifiers/settingsContentToStatic.mts +148 -0
  86. package/scripts/electronWorkflow/modifiers/wrapChildrenWithClientOnly.mts +73 -0
  87. package/src/app/[variants]/(main)/agent/cron/[cronId]/CronConfig.ts +16 -16
  88. package/src/app/[variants]/(main)/agent/cron/[cronId]/features/CronJobSaveButton.tsx +1 -1
  89. package/src/app/[variants]/(main)/agent/cron/[cronId]/features/CronJobScheduleConfig.tsx +5 -2
  90. package/src/app/[variants]/(main)/community/features/Search.tsx +1 -1
  91. package/src/app/[variants]/(main)/home/features/InputArea/SkillInstallBanner.tsx +131 -0
  92. package/src/app/[variants]/(main)/home/features/InputArea/index.tsx +34 -27
  93. package/src/app/[variants]/(main)/settings/features/SettingHeader.tsx +8 -4
  94. package/src/app/[variants]/(main)/settings/features/SettingsContent.tsx +3 -0
  95. package/src/app/[variants]/(main)/settings/hooks/useCategory.tsx +6 -0
  96. package/src/{features/PluginStore/InstalledList/List/Item/Action.tsx → app/[variants]/(main)/settings/skill/features/Actions.tsx} +45 -40
  97. package/src/app/[variants]/(main)/settings/skill/features/KlavisSkillItem.tsx +353 -0
  98. package/src/app/[variants]/(main)/settings/skill/features/LobehubSkillItem.tsx +344 -0
  99. package/src/app/[variants]/(main)/settings/skill/features/McpSkillItem.tsx +116 -0
  100. package/src/app/[variants]/(main)/settings/skill/features/SkillList.tsx +244 -0
  101. package/src/app/[variants]/(main)/settings/skill/index.tsx +35 -0
  102. package/src/app/[variants]/(mobile)/router/mobileRouter.config.tsx +27 -0
  103. package/src/app/[variants]/(mobile)/settings/_layout/Header.tsx +8 -17
  104. package/src/app/[variants]/(mobile)/settings/_layout/index.tsx +6 -1
  105. package/src/app/[variants]/(mobile)/settings/provider/_layout/index.tsx +22 -0
  106. package/src/components/Plugins/PluginTag.tsx +23 -35
  107. package/src/components/client/ClientOnly.tsx +6 -2
  108. package/src/features/AgentSetting/AgentPlugin/index.tsx +2 -2
  109. package/src/features/ChatInput/ActionBar/Tools/KlavisServerItem.tsx +8 -32
  110. package/src/features/ChatInput/ActionBar/Tools/LobehubSkillServerItem.tsx +8 -30
  111. package/src/features/ChatInput/ActionBar/Tools/PopoverContent.tsx +48 -59
  112. package/src/features/ChatInput/ActionBar/Tools/index.tsx +5 -23
  113. package/src/features/ChatInput/ActionBar/Tools/useControls.tsx +158 -56
  114. package/src/features/IntegrationDetailModal/index.tsx +293 -0
  115. package/src/features/{PluginStore/McpList/Detail → MCP/MCPDetail}/index.tsx +15 -6
  116. package/src/features/MCP/MCPSettings/McpSettingsModal.tsx +58 -0
  117. package/src/features/{PluginStore/McpList/Detail/Settings → MCP/MCPSettings}/index.tsx +39 -27
  118. package/src/features/PluginDetailModal/index.tsx +2 -2
  119. package/src/features/PluginDevModal/index.tsx +16 -40
  120. package/src/features/ProfileEditor/AgentTool.tsx +2 -2
  121. package/src/features/ProtocolUrlHandler/InstallPlugin/OfficialPluginInstallModal/index.tsx +1 -1
  122. package/src/features/{PluginStore/AddPluginButton.tsx → SkillStore/AddSkillButton.tsx} +3 -3
  123. package/src/features/SkillStore/CommunityList/Item.tsx +158 -0
  124. package/src/features/SkillStore/CommunityList/index.tsx +101 -0
  125. package/src/features/SkillStore/Content.tsx +59 -0
  126. package/src/features/{PluginStore/PluginEmpty.tsx → SkillStore/Empty.tsx} +8 -8
  127. package/src/features/SkillStore/LobeHubList/Item.tsx +118 -0
  128. package/src/features/SkillStore/LobeHubList/index.tsx +187 -0
  129. package/src/features/SkillStore/LobeHubList/useSkillConnect.ts +239 -0
  130. package/src/features/SkillStore/Search/index.tsx +43 -0
  131. package/src/features/{PluginStore → SkillStore}/index.tsx +14 -10
  132. package/src/features/SkillStore/style.ts +27 -0
  133. package/src/locales/default/plugin.ts +15 -4
  134. package/src/locales/default/setting.ts +204 -2
  135. package/src/services/chat/mecha/agentConfigResolver.test.ts +197 -0
  136. package/src/services/chat/mecha/agentConfigResolver.ts +44 -17
  137. package/src/store/chat/agents/GroupOrchestration/createGroupOrchestrationExecutors.ts +40 -37
  138. package/src/store/chat/slices/aiChat/actions/__tests__/streamingExecutor.test.ts +78 -0
  139. package/src/store/chat/slices/aiChat/actions/streamingExecutor.ts +50 -16
  140. package/src/store/global/initialState.ts +1 -0
  141. package/src/store/tool/slices/lobehubSkillStore/action.test.ts +914 -0
  142. package/src/store/tool/slices/lobehubSkillStore/selectors.test.ts +548 -0
  143. package/.cursor/skills/vercel-react-best-practices/AGENTS.md +0 -2410
  144. package/.cursor/skills/vercel-react-best-practices/SKILL.md +0 -125
  145. package/.cursor/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +0 -55
  146. package/.cursor/skills/vercel-react-best-practices/rules/advanced-use-latest.md +0 -49
  147. package/.cursor/skills/vercel-react-best-practices/rules/async-api-routes.md +0 -38
  148. package/.cursor/skills/vercel-react-best-practices/rules/async-defer-await.md +0 -80
  149. package/.cursor/skills/vercel-react-best-practices/rules/async-dependencies.md +0 -36
  150. package/.cursor/skills/vercel-react-best-practices/rules/async-parallel.md +0 -28
  151. package/.cursor/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +0 -99
  152. package/.cursor/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +0 -59
  153. package/.cursor/skills/vercel-react-best-practices/rules/bundle-conditional.md +0 -31
  154. package/.cursor/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +0 -49
  155. package/.cursor/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +0 -35
  156. package/.cursor/skills/vercel-react-best-practices/rules/bundle-preload.md +0 -50
  157. package/.cursor/skills/vercel-react-best-practices/rules/client-event-listeners.md +0 -74
  158. package/.cursor/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +0 -71
  159. package/.cursor/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +0 -48
  160. package/.cursor/skills/vercel-react-best-practices/rules/client-swr-dedup.md +0 -56
  161. package/.cursor/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +0 -57
  162. package/.cursor/skills/vercel-react-best-practices/rules/js-cache-function-results.md +0 -80
  163. package/.cursor/skills/vercel-react-best-practices/rules/js-cache-property-access.md +0 -28
  164. package/.cursor/skills/vercel-react-best-practices/rules/js-cache-storage.md +0 -70
  165. package/.cursor/skills/vercel-react-best-practices/rules/js-combine-iterations.md +0 -32
  166. package/.cursor/skills/vercel-react-best-practices/rules/js-early-exit.md +0 -50
  167. package/.cursor/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +0 -45
  168. package/.cursor/skills/vercel-react-best-practices/rules/js-index-maps.md +0 -37
  169. package/.cursor/skills/vercel-react-best-practices/rules/js-length-check-first.md +0 -49
  170. package/.cursor/skills/vercel-react-best-practices/rules/js-min-max-loop.md +0 -82
  171. package/.cursor/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +0 -24
  172. package/.cursor/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +0 -57
  173. package/.cursor/skills/vercel-react-best-practices/rules/rendering-activity.md +0 -26
  174. package/.cursor/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +0 -47
  175. package/.cursor/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +0 -40
  176. package/.cursor/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +0 -38
  177. package/.cursor/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +0 -46
  178. package/.cursor/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +0 -82
  179. package/.cursor/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +0 -28
  180. package/.cursor/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +0 -39
  181. package/.cursor/skills/vercel-react-best-practices/rules/rerender-dependencies.md +0 -45
  182. package/.cursor/skills/vercel-react-best-practices/rules/rerender-derived-state.md +0 -29
  183. package/.cursor/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +0 -74
  184. package/.cursor/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +0 -58
  185. package/.cursor/skills/vercel-react-best-practices/rules/rerender-memo.md +0 -44
  186. package/.cursor/skills/vercel-react-best-practices/rules/rerender-transitions.md +0 -40
  187. package/.cursor/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +0 -73
  188. package/.cursor/skills/vercel-react-best-practices/rules/server-cache-lru.md +0 -41
  189. package/.cursor/skills/vercel-react-best-practices/rules/server-cache-react.md +0 -76
  190. package/.cursor/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +0 -83
  191. package/.cursor/skills/vercel-react-best-practices/rules/server-serialization.md +0 -38
  192. package/src/features/PluginStore/Content.tsx +0 -54
  193. package/src/features/PluginStore/InstalledList/Detail/CustomPluginEmptyState.tsx +0 -79
  194. package/src/features/PluginStore/InstalledList/Detail/index.tsx +0 -21
  195. package/src/features/PluginStore/InstalledList/List/Item/index.tsx +0 -61
  196. package/src/features/PluginStore/InstalledList/List/index.tsx +0 -72
  197. package/src/features/PluginStore/InstalledList/index.tsx +0 -90
  198. package/src/features/PluginStore/McpList/List/Action.tsx +0 -119
  199. package/src/features/PluginStore/McpList/List/Item.tsx +0 -83
  200. package/src/features/PluginStore/McpList/List/index.tsx +0 -93
  201. package/src/features/PluginStore/McpList/index.tsx +0 -58
  202. package/src/features/PluginStore/PluginList/Detail/DetailProvider.tsx +0 -19
  203. package/src/features/PluginStore/PluginList/Detail/EmptyState.tsx +0 -56
  204. package/src/features/PluginStore/PluginList/Detail/Header.tsx +0 -130
  205. package/src/features/PluginStore/PluginList/Detail/InstallDetail/Nav.tsx +0 -73
  206. package/src/features/PluginStore/PluginList/Detail/InstallDetail/Settings.tsx +0 -19
  207. package/src/features/PluginStore/PluginList/Detail/InstallDetail/Tools.tsx +0 -111
  208. package/src/features/PluginStore/PluginList/Detail/InstallDetail/index.tsx +0 -24
  209. package/src/features/PluginStore/PluginList/Detail/Loading.tsx +0 -42
  210. package/src/features/PluginStore/PluginList/Detail/TagList.tsx +0 -35
  211. package/src/features/PluginStore/PluginList/Detail/index.tsx +0 -39
  212. package/src/features/PluginStore/PluginList/Detail/useCategory.tsx +0 -76
  213. package/src/features/PluginStore/PluginList/List/Action.tsx +0 -78
  214. package/src/features/PluginStore/PluginList/List/Item.tsx +0 -92
  215. package/src/features/PluginStore/PluginList/List/index.tsx +0 -94
  216. package/src/features/PluginStore/PluginList/index.tsx +0 -46
  217. package/src/features/PluginStore/Search/index.tsx +0 -40
  218. /package/{.codex/skills → .agents}/vercel-react-best-practices/AGENTS.md +0 -0
  219. /package/{.codex/skills → .agents}/vercel-react-best-practices/SKILL.md +0 -0
  220. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/advanced-event-handler-refs.md +0 -0
  221. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/advanced-use-latest.md +0 -0
  222. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/async-api-routes.md +0 -0
  223. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/async-defer-await.md +0 -0
  224. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/async-dependencies.md +0 -0
  225. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/async-parallel.md +0 -0
  226. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/async-suspense-boundaries.md +0 -0
  227. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/bundle-barrel-imports.md +0 -0
  228. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/bundle-conditional.md +0 -0
  229. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/bundle-defer-third-party.md +0 -0
  230. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/bundle-dynamic-imports.md +0 -0
  231. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/bundle-preload.md +0 -0
  232. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/client-event-listeners.md +0 -0
  233. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/client-localstorage-schema.md +0 -0
  234. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/client-passive-event-listeners.md +0 -0
  235. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/client-swr-dedup.md +0 -0
  236. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-batch-dom-css.md +0 -0
  237. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-cache-function-results.md +0 -0
  238. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-cache-property-access.md +0 -0
  239. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-cache-storage.md +0 -0
  240. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-combine-iterations.md +0 -0
  241. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-early-exit.md +0 -0
  242. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-hoist-regexp.md +0 -0
  243. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-index-maps.md +0 -0
  244. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-length-check-first.md +0 -0
  245. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-min-max-loop.md +0 -0
  246. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-set-map-lookups.md +0 -0
  247. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/js-tosorted-immutable.md +0 -0
  248. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rendering-activity.md +0 -0
  249. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +0 -0
  250. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rendering-conditional-render.md +0 -0
  251. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rendering-content-visibility.md +0 -0
  252. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rendering-hoist-jsx.md +0 -0
  253. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +0 -0
  254. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rendering-svg-precision.md +0 -0
  255. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rerender-defer-reads.md +0 -0
  256. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rerender-dependencies.md +0 -0
  257. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rerender-derived-state.md +0 -0
  258. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rerender-functional-setstate.md +0 -0
  259. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rerender-lazy-state-init.md +0 -0
  260. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rerender-memo.md +0 -0
  261. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/rerender-transitions.md +0 -0
  262. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/server-after-nonblocking.md +0 -0
  263. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/server-cache-lru.md +0 -0
  264. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/server-cache-react.md +0 -0
  265. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/server-parallel-fetching.md +0 -0
  266. /package/{.codex/skills → .agents}/vercel-react-best-practices/rules/server-serialization.md +0 -0
  267. /package/src/{features/PluginStore/InstalledList → app/[variants]/(main)/settings/skill/features}/EditCustomPlugin.tsx +0 -0
  268. /package/src/features/{PluginStore/McpList/Detail → MCP/MCPDetail}/Loading.tsx +0 -0
  269. /package/src/features/{PluginStore → SkillStore}/Loading.tsx +0 -0
  270. /package/src/features/{PluginStore → SkillStore}/VirtuosoLoading.tsx +0 -0
@@ -1,125 +0,0 @@
1
- ---
2
- name: vercel-react-best-practices
3
- description: React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
4
- license: MIT
5
- metadata:
6
- author: vercel
7
- version: "1.0.0"
8
- ---
9
-
10
- # Vercel React Best Practices
11
-
12
- Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 45 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
13
-
14
- ## When to Apply
15
-
16
- Reference these guidelines when:
17
- - Writing new React components or Next.js pages
18
- - Implementing data fetching (client or server-side)
19
- - Reviewing code for performance issues
20
- - Refactoring existing React/Next.js code
21
- - Optimizing bundle size or load times
22
-
23
- ## Rule Categories by Priority
24
-
25
- | Priority | Category | Impact | Prefix |
26
- |----------|----------|--------|--------|
27
- | 1 | Eliminating Waterfalls | CRITICAL | `async-` |
28
- | 2 | Bundle Size Optimization | CRITICAL | `bundle-` |
29
- | 3 | Server-Side Performance | HIGH | `server-` |
30
- | 4 | Client-Side Data Fetching | MEDIUM-HIGH | `client-` |
31
- | 5 | Re-render Optimization | MEDIUM | `rerender-` |
32
- | 6 | Rendering Performance | MEDIUM | `rendering-` |
33
- | 7 | JavaScript Performance | LOW-MEDIUM | `js-` |
34
- | 8 | Advanced Patterns | LOW | `advanced-` |
35
-
36
- ## Quick Reference
37
-
38
- ### 1. Eliminating Waterfalls (CRITICAL)
39
-
40
- - `async-defer-await` - Move await into branches where actually used
41
- - `async-parallel` - Use Promise.all() for independent operations
42
- - `async-dependencies` - Use better-all for partial dependencies
43
- - `async-api-routes` - Start promises early, await late in API routes
44
- - `async-suspense-boundaries` - Use Suspense to stream content
45
-
46
- ### 2. Bundle Size Optimization (CRITICAL)
47
-
48
- - `bundle-barrel-imports` - Import directly, avoid barrel files
49
- - `bundle-dynamic-imports` - Use next/dynamic for heavy components
50
- - `bundle-defer-third-party` - Load analytics/logging after hydration
51
- - `bundle-conditional` - Load modules only when feature is activated
52
- - `bundle-preload` - Preload on hover/focus for perceived speed
53
-
54
- ### 3. Server-Side Performance (HIGH)
55
-
56
- - `server-cache-react` - Use React.cache() for per-request deduplication
57
- - `server-cache-lru` - Use LRU cache for cross-request caching
58
- - `server-serialization` - Minimize data passed to client components
59
- - `server-parallel-fetching` - Restructure components to parallelize fetches
60
- - `server-after-nonblocking` - Use after() for non-blocking operations
61
-
62
- ### 4. Client-Side Data Fetching (MEDIUM-HIGH)
63
-
64
- - `client-swr-dedup` - Use SWR for automatic request deduplication
65
- - `client-event-listeners` - Deduplicate global event listeners
66
-
67
- ### 5. Re-render Optimization (MEDIUM)
68
-
69
- - `rerender-defer-reads` - Don't subscribe to state only used in callbacks
70
- - `rerender-memo` - Extract expensive work into memoized components
71
- - `rerender-dependencies` - Use primitive dependencies in effects
72
- - `rerender-derived-state` - Subscribe to derived booleans, not raw values
73
- - `rerender-functional-setstate` - Use functional setState for stable callbacks
74
- - `rerender-lazy-state-init` - Pass function to useState for expensive values
75
- - `rerender-transitions` - Use startTransition for non-urgent updates
76
-
77
- ### 6. Rendering Performance (MEDIUM)
78
-
79
- - `rendering-animate-svg-wrapper` - Animate div wrapper, not SVG element
80
- - `rendering-content-visibility` - Use content-visibility for long lists
81
- - `rendering-hoist-jsx` - Extract static JSX outside components
82
- - `rendering-svg-precision` - Reduce SVG coordinate precision
83
- - `rendering-hydration-no-flicker` - Use inline script for client-only data
84
- - `rendering-activity` - Use Activity component for show/hide
85
- - `rendering-conditional-render` - Use ternary, not && for conditionals
86
-
87
- ### 7. JavaScript Performance (LOW-MEDIUM)
88
-
89
- - `js-batch-dom-css` - Group CSS changes via classes or cssText
90
- - `js-index-maps` - Build Map for repeated lookups
91
- - `js-cache-property-access` - Cache object properties in loops
92
- - `js-cache-function-results` - Cache function results in module-level Map
93
- - `js-cache-storage` - Cache localStorage/sessionStorage reads
94
- - `js-combine-iterations` - Combine multiple filter/map into one loop
95
- - `js-length-check-first` - Check array length before expensive comparison
96
- - `js-early-exit` - Return early from functions
97
- - `js-hoist-regexp` - Hoist RegExp creation outside loops
98
- - `js-min-max-loop` - Use loop for min/max instead of sort
99
- - `js-set-map-lookups` - Use Set/Map for O(1) lookups
100
- - `js-tosorted-immutable` - Use toSorted() for immutability
101
-
102
- ### 8. Advanced Patterns (LOW)
103
-
104
- - `advanced-event-handler-refs` - Store event handlers in refs
105
- - `advanced-use-latest` - useLatest for stable callback refs
106
-
107
- ## How to Use
108
-
109
- Read individual rule files for detailed explanations and code examples:
110
-
111
- ```
112
- rules/async-parallel.md
113
- rules/bundle-barrel-imports.md
114
- rules/_sections.md
115
- ```
116
-
117
- Each rule file contains:
118
- - Brief explanation of why it matters
119
- - Incorrect code example with explanation
120
- - Correct code example with explanation
121
- - Additional context and references
122
-
123
- ## Full Compiled Document
124
-
125
- For the complete guide with all rules expanded: `AGENTS.md`
@@ -1,55 +0,0 @@
1
- ---
2
- title: Store Event Handlers in Refs
3
- impact: LOW
4
- impactDescription: stable subscriptions
5
- tags: advanced, hooks, refs, event-handlers, optimization
6
- ---
7
-
8
- ## Store Event Handlers in Refs
9
-
10
- Store callbacks in refs when used in effects that shouldn't re-subscribe on callback changes.
11
-
12
- **Incorrect (re-subscribes on every render):**
13
-
14
- ```tsx
15
- function useWindowEvent(event: string, handler: (e) => void) {
16
- useEffect(() => {
17
- window.addEventListener(event, handler)
18
- return () => window.removeEventListener(event, handler)
19
- }, [event, handler])
20
- }
21
- ```
22
-
23
- **Correct (stable subscription):**
24
-
25
- ```tsx
26
- function useWindowEvent(event: string, handler: (e) => void) {
27
- const handlerRef = useRef(handler)
28
- useEffect(() => {
29
- handlerRef.current = handler
30
- }, [handler])
31
-
32
- useEffect(() => {
33
- const listener = (e) => handlerRef.current(e)
34
- window.addEventListener(event, listener)
35
- return () => window.removeEventListener(event, listener)
36
- }, [event])
37
- }
38
- ```
39
-
40
- **Alternative: use `useEffectEvent` if you're on latest React:**
41
-
42
- ```tsx
43
- import { useEffectEvent } from 'react'
44
-
45
- function useWindowEvent(event: string, handler: (e) => void) {
46
- const onEvent = useEffectEvent(handler)
47
-
48
- useEffect(() => {
49
- window.addEventListener(event, onEvent)
50
- return () => window.removeEventListener(event, onEvent)
51
- }, [event])
52
- }
53
- ```
54
-
55
- `useEffectEvent` provides a cleaner API for the same pattern: it creates a stable function reference that always calls the latest version of the handler.
@@ -1,49 +0,0 @@
1
- ---
2
- title: useLatest for Stable Callback Refs
3
- impact: LOW
4
- impactDescription: prevents effect re-runs
5
- tags: advanced, hooks, useLatest, refs, optimization
6
- ---
7
-
8
- ## useLatest for Stable Callback Refs
9
-
10
- Access latest values in callbacks without adding them to dependency arrays. Prevents effect re-runs while avoiding stale closures.
11
-
12
- **Implementation:**
13
-
14
- ```typescript
15
- function useLatest<T>(value: T) {
16
- const ref = useRef(value)
17
- useLayoutEffect(() => {
18
- ref.current = value
19
- }, [value])
20
- return ref
21
- }
22
- ```
23
-
24
- **Incorrect (effect re-runs on every callback change):**
25
-
26
- ```tsx
27
- function SearchInput({ onSearch }: { onSearch: (q: string) => void }) {
28
- const [query, setQuery] = useState('')
29
-
30
- useEffect(() => {
31
- const timeout = setTimeout(() => onSearch(query), 300)
32
- return () => clearTimeout(timeout)
33
- }, [query, onSearch])
34
- }
35
- ```
36
-
37
- **Correct (stable effect, fresh callback):**
38
-
39
- ```tsx
40
- function SearchInput({ onSearch }: { onSearch: (q: string) => void }) {
41
- const [query, setQuery] = useState('')
42
- const onSearchRef = useLatest(onSearch)
43
-
44
- useEffect(() => {
45
- const timeout = setTimeout(() => onSearchRef.current(query), 300)
46
- return () => clearTimeout(timeout)
47
- }, [query])
48
- }
49
- ```
@@ -1,38 +0,0 @@
1
- ---
2
- title: Prevent Waterfall Chains in API Routes
3
- impact: CRITICAL
4
- impactDescription: 2-10× improvement
5
- tags: api-routes, server-actions, waterfalls, parallelization
6
- ---
7
-
8
- ## Prevent Waterfall Chains in API Routes
9
-
10
- In API routes and Server Actions, start independent operations immediately, even if you don't await them yet.
11
-
12
- **Incorrect (config waits for auth, data waits for both):**
13
-
14
- ```typescript
15
- export async function GET(request: Request) {
16
- const session = await auth()
17
- const config = await fetchConfig()
18
- const data = await fetchData(session.user.id)
19
- return Response.json({ data, config })
20
- }
21
- ```
22
-
23
- **Correct (auth and config start immediately):**
24
-
25
- ```typescript
26
- export async function GET(request: Request) {
27
- const sessionPromise = auth()
28
- const configPromise = fetchConfig()
29
- const session = await sessionPromise
30
- const [config, data] = await Promise.all([
31
- configPromise,
32
- fetchData(session.user.id)
33
- ])
34
- return Response.json({ data, config })
35
- }
36
- ```
37
-
38
- For operations with more complex dependency chains, use `better-all` to automatically maximize parallelism (see Dependency-Based Parallelization).
@@ -1,80 +0,0 @@
1
- ---
2
- title: Defer Await Until Needed
3
- impact: HIGH
4
- impactDescription: avoids blocking unused code paths
5
- tags: async, await, conditional, optimization
6
- ---
7
-
8
- ## Defer Await Until Needed
9
-
10
- Move `await` operations into the branches where they're actually used to avoid blocking code paths that don't need them.
11
-
12
- **Incorrect (blocks both branches):**
13
-
14
- ```typescript
15
- async function handleRequest(userId: string, skipProcessing: boolean) {
16
- const userData = await fetchUserData(userId)
17
-
18
- if (skipProcessing) {
19
- // Returns immediately but still waited for userData
20
- return { skipped: true }
21
- }
22
-
23
- // Only this branch uses userData
24
- return processUserData(userData)
25
- }
26
- ```
27
-
28
- **Correct (only blocks when needed):**
29
-
30
- ```typescript
31
- async function handleRequest(userId: string, skipProcessing: boolean) {
32
- if (skipProcessing) {
33
- // Returns immediately without waiting
34
- return { skipped: true }
35
- }
36
-
37
- // Fetch only when needed
38
- const userData = await fetchUserData(userId)
39
- return processUserData(userData)
40
- }
41
- ```
42
-
43
- **Another example (early return optimization):**
44
-
45
- ```typescript
46
- // Incorrect: always fetches permissions
47
- async function updateResource(resourceId: string, userId: string) {
48
- const permissions = await fetchPermissions(userId)
49
- const resource = await getResource(resourceId)
50
-
51
- if (!resource) {
52
- return { error: 'Not found' }
53
- }
54
-
55
- if (!permissions.canEdit) {
56
- return { error: 'Forbidden' }
57
- }
58
-
59
- return await updateResourceData(resource, permissions)
60
- }
61
-
62
- // Correct: fetches only when needed
63
- async function updateResource(resourceId: string, userId: string) {
64
- const resource = await getResource(resourceId)
65
-
66
- if (!resource) {
67
- return { error: 'Not found' }
68
- }
69
-
70
- const permissions = await fetchPermissions(userId)
71
-
72
- if (!permissions.canEdit) {
73
- return { error: 'Forbidden' }
74
- }
75
-
76
- return await updateResourceData(resource, permissions)
77
- }
78
- ```
79
-
80
- This optimization is especially valuable when the skipped branch is frequently taken, or when the deferred operation is expensive.
@@ -1,36 +0,0 @@
1
- ---
2
- title: Dependency-Based Parallelization
3
- impact: CRITICAL
4
- impactDescription: 2-10× improvement
5
- tags: async, parallelization, dependencies, better-all
6
- ---
7
-
8
- ## Dependency-Based Parallelization
9
-
10
- For operations with partial dependencies, use `better-all` to maximize parallelism. It automatically starts each task at the earliest possible moment.
11
-
12
- **Incorrect (profile waits for config unnecessarily):**
13
-
14
- ```typescript
15
- const [user, config] = await Promise.all([
16
- fetchUser(),
17
- fetchConfig()
18
- ])
19
- const profile = await fetchProfile(user.id)
20
- ```
21
-
22
- **Correct (config and profile run in parallel):**
23
-
24
- ```typescript
25
- import { all } from 'better-all'
26
-
27
- const { user, config, profile } = await all({
28
- async user() { return fetchUser() },
29
- async config() { return fetchConfig() },
30
- async profile() {
31
- return fetchProfile((await this.$.user).id)
32
- }
33
- })
34
- ```
35
-
36
- Reference: [https://github.com/shuding/better-all](https://github.com/shuding/better-all)
@@ -1,28 +0,0 @@
1
- ---
2
- title: Promise.all() for Independent Operations
3
- impact: CRITICAL
4
- impactDescription: 2-10× improvement
5
- tags: async, parallelization, promises, waterfalls
6
- ---
7
-
8
- ## Promise.all() for Independent Operations
9
-
10
- When async operations have no interdependencies, execute them concurrently using `Promise.all()`.
11
-
12
- **Incorrect (sequential execution, 3 round trips):**
13
-
14
- ```typescript
15
- const user = await fetchUser()
16
- const posts = await fetchPosts()
17
- const comments = await fetchComments()
18
- ```
19
-
20
- **Correct (parallel execution, 1 round trip):**
21
-
22
- ```typescript
23
- const [user, posts, comments] = await Promise.all([
24
- fetchUser(),
25
- fetchPosts(),
26
- fetchComments()
27
- ])
28
- ```
@@ -1,99 +0,0 @@
1
- ---
2
- title: Strategic Suspense Boundaries
3
- impact: HIGH
4
- impactDescription: faster initial paint
5
- tags: async, suspense, streaming, layout-shift
6
- ---
7
-
8
- ## Strategic Suspense Boundaries
9
-
10
- Instead of awaiting data in async components before returning JSX, use Suspense boundaries to show the wrapper UI faster while data loads.
11
-
12
- **Incorrect (wrapper blocked by data fetching):**
13
-
14
- ```tsx
15
- async function Page() {
16
- const data = await fetchData() // Blocks entire page
17
-
18
- return (
19
- <div>
20
- <div>Sidebar</div>
21
- <div>Header</div>
22
- <div>
23
- <DataDisplay data={data} />
24
- </div>
25
- <div>Footer</div>
26
- </div>
27
- )
28
- }
29
- ```
30
-
31
- The entire layout waits for data even though only the middle section needs it.
32
-
33
- **Correct (wrapper shows immediately, data streams in):**
34
-
35
- ```tsx
36
- function Page() {
37
- return (
38
- <div>
39
- <div>Sidebar</div>
40
- <div>Header</div>
41
- <div>
42
- <Suspense fallback={<Skeleton />}>
43
- <DataDisplay />
44
- </Suspense>
45
- </div>
46
- <div>Footer</div>
47
- </div>
48
- )
49
- }
50
-
51
- async function DataDisplay() {
52
- const data = await fetchData() // Only blocks this component
53
- return <div>{data.content}</div>
54
- }
55
- ```
56
-
57
- Sidebar, Header, and Footer render immediately. Only DataDisplay waits for data.
58
-
59
- **Alternative (share promise across components):**
60
-
61
- ```tsx
62
- function Page() {
63
- // Start fetch immediately, but don't await
64
- const dataPromise = fetchData()
65
-
66
- return (
67
- <div>
68
- <div>Sidebar</div>
69
- <div>Header</div>
70
- <Suspense fallback={<Skeleton />}>
71
- <DataDisplay dataPromise={dataPromise} />
72
- <DataSummary dataPromise={dataPromise} />
73
- </Suspense>
74
- <div>Footer</div>
75
- </div>
76
- )
77
- }
78
-
79
- function DataDisplay({ dataPromise }: { dataPromise: Promise<Data> }) {
80
- const data = use(dataPromise) // Unwraps the promise
81
- return <div>{data.content}</div>
82
- }
83
-
84
- function DataSummary({ dataPromise }: { dataPromise: Promise<Data> }) {
85
- const data = use(dataPromise) // Reuses the same promise
86
- return <div>{data.summary}</div>
87
- }
88
- ```
89
-
90
- Both components share the same promise, so only one fetch occurs. Layout renders immediately while both components wait together.
91
-
92
- **When NOT to use this pattern:**
93
-
94
- - Critical data needed for layout decisions (affects positioning)
95
- - SEO-critical content above the fold
96
- - Small, fast queries where suspense overhead isn't worth it
97
- - When you want to avoid layout shift (loading → content jump)
98
-
99
- **Trade-off:** Faster initial paint vs potential layout shift. Choose based on your UX priorities.
@@ -1,59 +0,0 @@
1
- ---
2
- title: Avoid Barrel File Imports
3
- impact: CRITICAL
4
- impactDescription: 200-800ms import cost, slow builds
5
- tags: bundle, imports, tree-shaking, barrel-files, performance
6
- ---
7
-
8
- ## Avoid Barrel File Imports
9
-
10
- Import directly from source files instead of barrel files to avoid loading thousands of unused modules. **Barrel files** are entry points that re-export multiple modules (e.g., `index.js` that does `export * from './module'`).
11
-
12
- Popular icon and component libraries can have **up to 10,000 re-exports** in their entry file. For many React packages, **it takes 200-800ms just to import them**, affecting both development speed and production cold starts.
13
-
14
- **Why tree-shaking doesn't help:** When a library is marked as external (not bundled), the bundler can't optimize it. If you bundle it to enable tree-shaking, builds become substantially slower analyzing the entire module graph.
15
-
16
- **Incorrect (imports entire library):**
17
-
18
- ```tsx
19
- import { Check, X, Menu } from 'lucide-react'
20
- // Loads 1,583 modules, takes ~2.8s extra in dev
21
- // Runtime cost: 200-800ms on every cold start
22
-
23
- import { Button, TextField } from '@mui/material'
24
- // Loads 2,225 modules, takes ~4.2s extra in dev
25
- ```
26
-
27
- **Correct (imports only what you need):**
28
-
29
- ```tsx
30
- import Check from 'lucide-react/dist/esm/icons/check'
31
- import X from 'lucide-react/dist/esm/icons/x'
32
- import Menu from 'lucide-react/dist/esm/icons/menu'
33
- // Loads only 3 modules (~2KB vs ~1MB)
34
-
35
- import Button from '@mui/material/Button'
36
- import TextField from '@mui/material/TextField'
37
- // Loads only what you use
38
- ```
39
-
40
- **Alternative (Next.js 13.5+):**
41
-
42
- ```js
43
- // next.config.js - use optimizePackageImports
44
- module.exports = {
45
- experimental: {
46
- optimizePackageImports: ['lucide-react', '@mui/material']
47
- }
48
- }
49
-
50
- // Then you can keep the ergonomic barrel imports:
51
- import { Check, X, Menu } from 'lucide-react'
52
- // Automatically transformed to direct imports at build time
53
- ```
54
-
55
- Direct imports provide 15-70% faster dev boot, 28% faster builds, 40% faster cold starts, and significantly faster HMR.
56
-
57
- Libraries commonly affected: `lucide-react`, `@mui/material`, `@mui/icons-material`, `@tabler/icons-react`, `react-icons`, `@headlessui/react`, `@radix-ui/react-*`, `lodash`, `ramda`, `date-fns`, `rxjs`, `react-use`.
58
-
59
- Reference: [How we optimized package imports in Next.js](https://vercel.com/blog/how-we-optimized-package-imports-in-next-js)
@@ -1,31 +0,0 @@
1
- ---
2
- title: Conditional Module Loading
3
- impact: HIGH
4
- impactDescription: loads large data only when needed
5
- tags: bundle, conditional-loading, lazy-loading
6
- ---
7
-
8
- ## Conditional Module Loading
9
-
10
- Load large data or modules only when a feature is activated.
11
-
12
- **Example (lazy-load animation frames):**
13
-
14
- ```tsx
15
- function AnimationPlayer({ enabled, setEnabled }: { enabled: boolean; setEnabled: React.Dispatch<React.SetStateAction<boolean>> }) {
16
- const [frames, setFrames] = useState<Frame[] | null>(null)
17
-
18
- useEffect(() => {
19
- if (enabled && !frames && typeof window !== 'undefined') {
20
- import('./animation-frames.js')
21
- .then(mod => setFrames(mod.frames))
22
- .catch(() => setEnabled(false))
23
- }
24
- }, [enabled, frames, setEnabled])
25
-
26
- if (!frames) return <Skeleton />
27
- return <Canvas frames={frames} />
28
- }
29
- ```
30
-
31
- The `typeof window !== 'undefined'` check prevents bundling this module for SSR, optimizing server bundle size and build speed.
@@ -1,49 +0,0 @@
1
- ---
2
- title: Defer Non-Critical Third-Party Libraries
3
- impact: MEDIUM
4
- impactDescription: loads after hydration
5
- tags: bundle, third-party, analytics, defer
6
- ---
7
-
8
- ## Defer Non-Critical Third-Party Libraries
9
-
10
- Analytics, logging, and error tracking don't block user interaction. Load them after hydration.
11
-
12
- **Incorrect (blocks initial bundle):**
13
-
14
- ```tsx
15
- import { Analytics } from '@vercel/analytics/react'
16
-
17
- export default function RootLayout({ children }) {
18
- return (
19
- <html>
20
- <body>
21
- {children}
22
- <Analytics />
23
- </body>
24
- </html>
25
- )
26
- }
27
- ```
28
-
29
- **Correct (loads after hydration):**
30
-
31
- ```tsx
32
- import dynamic from 'next/dynamic'
33
-
34
- const Analytics = dynamic(
35
- () => import('@vercel/analytics/react').then(m => m.Analytics),
36
- { ssr: false }
37
- )
38
-
39
- export default function RootLayout({ children }) {
40
- return (
41
- <html>
42
- <body>
43
- {children}
44
- <Analytics />
45
- </body>
46
- </html>
47
- )
48
- }
49
- ```
@@ -1,35 +0,0 @@
1
- ---
2
- title: Dynamic Imports for Heavy Components
3
- impact: CRITICAL
4
- impactDescription: directly affects TTI and LCP
5
- tags: bundle, dynamic-import, code-splitting, next-dynamic
6
- ---
7
-
8
- ## Dynamic Imports for Heavy Components
9
-
10
- Use `next/dynamic` to lazy-load large components not needed on initial render.
11
-
12
- **Incorrect (Monaco bundles with main chunk ~300KB):**
13
-
14
- ```tsx
15
- import { MonacoEditor } from './monaco-editor'
16
-
17
- function CodePanel({ code }: { code: string }) {
18
- return <MonacoEditor value={code} />
19
- }
20
- ```
21
-
22
- **Correct (Monaco loads on demand):**
23
-
24
- ```tsx
25
- import dynamic from 'next/dynamic'
26
-
27
- const MonacoEditor = dynamic(
28
- () => import('./monaco-editor').then(m => m.MonacoEditor),
29
- { ssr: false }
30
- )
31
-
32
- function CodePanel({ code }: { code: string }) {
33
- return <MonacoEditor value={code} />
34
- }
35
- ```