-
Notifications
You must be signed in to change notification settings - Fork 0
Implement RemoteView #1
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
base: main
Are you sure you want to change the base?
Conversation
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.
Performed full review of 4361e9a...3e7ea11
Analysis
-
State Management Race Conditions: The RemoteViewProvider implementation contains stale closure bugs in its error handling logic that could lead to lost errors or inconsistent application state.
-
Package Publishing Configuration: Critical build/publish configuration problems exist, including incorrect main field pointing to TypeScript source instead of compiled JavaScript, missing required package.json fields, and dependency management inconsistencies.
-
Security Model Weaknesses: Dynamic imports and CSS injection rely on documentation/comments about trusted sources rather than implementing runtime validation, creating potential security vulnerabilities.
-
Memory Management Issues: No mechanism exists to track or clean up injected CSS stylesheets, potentially leading to memory leaks in long-running applications.
-
Error Recovery Limitations: The system lacks built-in functionality for retrying failed loads without completely remounting the provider component.
Tip
Help
Slash Commands:
/review- Request a full code review/review latest- Review only changes since the last review/describe- Generate PR description. This will update the PR body or issue comment depending on your configuration/help- Get help with Mesa commands and configuration options
94 files reviewed | 8 comments | Edit Agent Settings • Read Docs
| LoadedView && setViews((prev) => ({ ...prev, [url]: LoadedView })); | ||
| }) | ||
| .catch((err: Error) => { | ||
| setErrors({ ...errors, [url]: err }); |
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 creates a stale closure bug. When the async catch block executes, it uses an outdated version of the errors state. This can cause errors to be overwritten or lost. Use functional state update: setErrors(prev => ({ ...prev, [url]: err })) to ensure you're working with the latest error state.
Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/modular#1
File: packages/remote-view/src/components/remote-view-provider.tsx#L112
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.
Feedback:
This creates a stale closure bug. When the async catch block executes, it uses an outdated version of the `errors` state. This can cause errors to be overwritten or lost. Use functional state update: `setErrors(prev => ({ ...prev, [url]: err }))` to ensure you're working with the latest error state.
| "modular": { | ||
| "type": "package" | ||
| }, | ||
| "main": "./src/index.ts", |
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.
The main field points to TypeScript source file ./src/index.ts, but this package is marked as public and will be published. Published packages should point to built JavaScript files, not TypeScript source. This will cause runtime errors for consumers. Change to point to built output like ./dist/index.js or ./lib/index.js.
Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/modular#1
File: packages/remote-view/package.json#L7
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.
Feedback:
The `main` field points to TypeScript source file `./src/index.ts`, but this package is marked as public and will be published. Published packages should point to built JavaScript files, not TypeScript source. This will cause runtime errors for consumers. Change to point to built output like `./dist/index.js` or `./lib/index.js`.
| const currentView = views[baseUrl]; | ||
|
|
||
| if (remoteViewError) { | ||
| throw new RemoteViewError(remoteViewError.message, baseUrl); |
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.
Creating a new RemoteViewError instance instead of re-throwing the existing error loses the original error context and stack trace. Consider re-throwing the existing error: throw remoteViewError to preserve debugging information.
Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/modular#1
File: packages/remote-view/src/hooks/useRemoteView.tsx#L14
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.
Feedback:
Creating a new RemoteViewError instance instead of re-throwing the existing error loses the original error context and stack trace. Consider re-throwing the existing error: `throw remoteViewError` to preserve debugging information.
| "modular": "ts-node packages/modular-scripts/src/cli.ts", | ||
| "test": "yarn modular test --watchAll false --runInBand --env node", | ||
| "build": "yarn workspace @modular-scripts/workspace-resolver build && yarn workspace create-modular-react-app build && yarn workspace modular-scripts build && yarn workspace modular-views.macro build", | ||
| "build": "yarn workspace @modular-scripts/workspace-resolver build && yarn workspace create-modular-react-app build && yarn workspace modular-scripts build && yarn workspace modular-views.macro build && yarn modular build @modular-scripts/remote-view", |
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.
The build script adds yarn modular build @modular-scripts/remote-view but the remote-view package doesn't have proper build configuration in its package.json. Since remote-view's main field points to source TypeScript files, this build command may not produce the expected built artifacts needed for publishing.
Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/modular#1
File: package.json#L18
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.
Feedback:
The build script adds `yarn modular build @modular-scripts/remote-view` but the remote-view package doesn't have proper build configuration in its package.json. Since remote-view's main field points to source TypeScript files, this build command may not produce the expected built artifacts needed for publishing.
| }, | ||
| "version": "0.0.0", | ||
| "dependencies": { | ||
| "@modular-scripts/remote-view": "*", |
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.
The dependency @modular-scripts/remote-view uses a wildcard version * which is problematic. Since this is an internal workspace dependency, it should use the workspace protocol: workspace:* to ensure it resolves to the local workspace package during development.
Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/modular#1
File: packages/remote-view-demos/package.json#L10
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.
Feedback:
The dependency `@modular-scripts/remote-view` uses a wildcard version `*` which is problematic. Since this is an internal workspace dependency, it should use the workspace protocol: `workspace:*` to ensure it resolves to the local workspace package during development.
| const ViewComponent = useRemoteView(url); | ||
| const loadingOutput = loading ? loading : <DefaultLoading />; | ||
|
|
||
| return (ViewComponent && <ViewComponent />) || loadingOutput; |
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.
The conditional rendering (ViewComponent && <ViewComponent />) || loadingOutput could be clearer. Consider using an explicit ternary operator: ViewComponent ? <ViewComponent /> : loadingOutput for better readability and intent.
Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/modular#1
File: packages/remote-view/src/components/remote-view.tsx#L17
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.
Feedback:
The conditional rendering `(ViewComponent && <ViewComponent />) || loadingOutput` could be clearer. Consider using an explicit ternary operator: `ViewComponent ? <ViewComponent /> : loadingOutput` for better readability and intent.
|
|
||
| // Create server | ||
| const server = http.createServer(function onRequest(req, res) { | ||
| res.setHeader('Access-Control-Allow-Origin', '*'); |
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.
The CORS configuration allows any domain (*) to access this test server. While acceptable for local testing, ensure this pattern isn't used in production. Production remote view servers should restrict CORS to specific trusted origins to prevent security issues.
Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/modular#1
File: packages/remote-view/src/__tests__/serve.js#L23
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.
Feedback:
The CORS configuration allows any domain (`*`) to access this test server. While acceptable for local testing, ensure this pattern isn't used in production. Production remote view servers should restrict CORS to specific trusted origins to prevent security issues.
| this.state = { error: undefined, isRemoteViewError: undefined }; | ||
| } | ||
|
|
||
| componentDidCatch( |
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.
Consider implementing static getDerivedStateFromError for state updates and keeping componentDidCatch only for logging, following React's recommended error boundary pattern. This separates concerns and ensures state updates happen at the right time in the component lifecycle.
Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/modular#1
File: packages/remote-view/src/components/remote-view-error-boundary.tsx#L25
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.
Feedback:
Consider implementing `static getDerivedStateFromError` for state updates and keeping `componentDidCatch` only for logging, following React's recommended error boundary pattern. This separates concerns and ensures state updates happen at the right time in the component lifecycle.
No description provided.