-
Notifications
You must be signed in to change notification settings - Fork 0
Implement lazy-loaded plugin architecture with self-contained type definitions #32
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
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
|
@copilot 插件是由第三方开发商开发的,需要重新思考这个类型应该写在哪里,我觉得类型应该写在插件的软件包中,然后安装的时候注册到平台中 |
This addresses the architectural concern that plugin types should be owned by the plugin packages themselves, not the core platform. This allows third-party developers to create plugins without modifying core packages. Changes: - Removed packages/types/src/plugin.ts (no longer needed) - Reverted packages/types/src/index.ts to remove plugin type exports - Added packages/plugin-editor/src/types.ts with CodeEditorSchema - Added packages/plugin-charts/src/types.ts with BarChartSchema - Updated plugin packages to export their types via index.tsx - Added @object-ui/types as dependency for plugins (for BaseSchema) - Updated documentation to explain plugin-owned types pattern Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
You're absolutely right! I've refactored the architecture to move plugin types into the plugin packages themselves instead of the core Changes made (commit d1fe645):
Benefits of this approach:
Usage: // Import types directly from plugin packages
import type { CodeEditorSchema } from '@object-ui/plugin-editor';
import type { BarChartSchema } from '@object-ui/plugin-charts';
const editor: CodeEditorSchema = { type: 'code-editor', value: '...' };Documentation has been updated to explain this pattern in |
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.
Pull request overview
This PR implements a lazy-loaded plugin architecture that splits heavy dependencies (Monaco Editor and Recharts) into separate chunks that load on-demand, reducing initial bundle size by ~355 KB. Each plugin internally manages lazy loading using React.lazy() and Suspense, so consumers only need to import the plugin package.
Changes:
- Created two plugin packages (
@object-ui/plugin-editorand@object-ui/plugin-charts) with self-contained type definitions - Implemented a two-file pattern (HeavyImpl.tsx for imports, index.tsx for lazy wrapper) to enable automatic code splitting
- Added playground examples and comprehensive documentation for the plugin architecture
Reviewed changes
Copilot reviewed 23 out of 24 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/plugin-editor/vite.config.ts | Build configuration for code editor plugin with externalized dependencies |
| packages/plugin-editor/tsconfig.json | TypeScript configuration for plugin-editor package |
| packages/plugin-editor/src/types.ts | Self-contained type definitions for code editor schema |
| packages/plugin-editor/src/index.tsx | Lazy wrapper with React.Suspense and component registration |
| packages/plugin-editor/src/MonacoImpl.tsx | Heavy implementation that imports Monaco Editor |
| packages/plugin-editor/package.json | Package manifest with Monaco Editor dependency |
| packages/plugin-editor/README.md | Usage documentation and architecture explanation |
| packages/plugin-charts/vite.config.ts | Build configuration for charts plugin with externalized dependencies |
| packages/plugin-charts/tsconfig.json | TypeScript configuration for plugin-charts package |
| packages/plugin-charts/src/types.ts | Self-contained type definitions for bar chart schema |
| packages/plugin-charts/src/index.tsx | Lazy wrapper with React.Suspense and component registration |
| packages/plugin-charts/src/ChartImpl.tsx | Heavy implementation that imports Recharts |
| packages/plugin-charts/package.json | Package manifest with Recharts dependency |
| packages/plugin-charts/README.md | Usage documentation and architecture explanation |
| docs/lazy-loaded-plugins.md | Comprehensive architecture reference and plugin creation guide |
| apps/playground/src/data/examples/plugins/*.json | Demo schemas showcasing plugin functionality |
| apps/playground/src/data/examples/plugins.ts | Plugin examples registry |
| apps/playground/src/data/examples.ts | Added plugins category to examples catalog |
| apps/playground/src/App.tsx | Side-effect imports for plugin registration |
| apps/playground/package.json | Added plugin package dependencies |
| VERIFICATION.md | Build verification report with bundle analysis |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
packages/plugin-charts/tsconfig.json:1
- Setting
noImplicitAnytofalsedisables an important type safety check. This should be set totrueto maintain strict TypeScript standards and catch potential type errors early.
packages/plugin-editor/tsconfig.json
Outdated
| "paths": { | ||
| "@/*": ["src/*"] | ||
| }, | ||
| "noImplicitAny": false, |
Copilot
AI
Jan 14, 2026
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.
Setting noImplicitAny to false disables an important type safety check. This should be set to true to maintain strict TypeScript standards and catch potential type errors early.
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.
Fixed in commit 0f673f9. Changed noImplicitAny from false to true in both plugin packages' tsconfig.json files to maintain strict TypeScript standards.
|
@copilot fix pnpm test |
- Remove test scripts from plugin packages (no test files exist) - Set noImplicitAny to true for better type safety - All tests now pass successfully Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Fixed in commit 0f673f9. Removed the |
|
✅ All checks passed!
|
✅ Refactor Monorepo to Support Lazy-Loaded Plugins - COMPLETE
Successfully implemented a lazy-loaded plugin architecture that keeps heavy components (Monaco Editor ~15KB, Recharts ~340KB) out of the main application bundle.
📋 What Was Built
1. Plugin Packages
@object-ui/plugin-editor- Monaco Code Editor@monaco-editor/reactcode-editor@object-ui/plugin-charts- Recharts Bar Chartsrechartschart-bar2. Type Architecture
Plugin-Owned Types - Each plugin owns its type definitions:
This allows third-party developers to create plugins without modifying core packages.
Usage:
3. Example Schemas
Created 3 playground examples:
plugins-showcase- Combined demo of both pluginscode-editor-demo- Multiple code editors with different languagescharts-demo- Multiple charts with different data4. Documentation
packages/plugin-editor/README.md- Usage guide (updated with type examples)packages/plugin-charts/README.md- Usage guide (updated with type examples)docs/lazy-loaded-plugins.md- Architecture documentation (added type system design section)VERIFICATION.md- Build verification report⚡ Lazy Loading Architecture
The Pattern
Each plugin uses a two-file approach:
Why This Matters
Without lazy loading:
With lazy loading:
Savings: ~355 KB (13.5%) on initial load for apps that don't use these on every page.
🎯 Build Verification
Plugin Build Output
plugin-editor:
plugin-charts:
Playground Build (Final App)
✅ Verification passed: Heavy chunks are NOT in main bundle
🚀 Usage
1. Install plugins
2. Import once (side-effect)
3. Use in schemas (with type safety)
That's it! The plugins handle all lazy loading internally.
📁 Recent Changes
Latest Update (Fix Tests & TypeScript):
testscripts from plugin packages (no test files exist)noImplicitAny: truefor better type safety in both pluginspnpm testsucceedsType Architecture Update:
packages/types/src/plugin.ts(types moved to plugins)packages/types/src/index.ts(removed plugin type exports)packages/plugin-editor/src/types.ts(plugin-owned types)packages/plugin-charts/src/types.ts(plugin-owned types)Plugin Packages:
packages/plugin-editor/src/index.tsx(export types)packages/plugin-charts/src/index.tsx(export types)packages/plugin-editor/package.json(add @object-ui/types dep)packages/plugin-charts/package.json(add @object-ui/types dep)Documentation:
packages/plugin-editor/README.md(TypeScript examples)packages/plugin-charts/README.md(TypeScript examples)docs/lazy-loaded-plugins.md(type system design section)✨ Key Benefits
noImplicitAny: truefor better type safety🧪 Testing
All packages tested successfully:
pnpm install- Dependencies installedpnpm build- All packages builtpnpm test- All tests pass (26 tests across 6 packages)Ready to merge! 🎉
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.