-
Notifications
You must be signed in to change notification settings - Fork 131
refactor(rivetkit): extract WebSocket protocol parsing to shared utility #3429
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: 11-09-refactor_rivetkit_restructure_connection_lifecycle_contexts
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Code Review for PR #3429SummaryThis PR successfully refactors WebSocket protocol parsing logic by extracting duplicated code into a shared utility function ✅ Positive Changes
🔍 Code Quality & Best PracticesIssue 1: Silent fallback behavior change in The PR changes // Before:
if (!encodingParam) {
throw new errors.InvalidEncoding("undefined");
}
// After:
if (!encodingParam) {
return "json";
}Concerns:
Recommendation: Consider one of these approaches:
Issue 2: Missing error handling in const encoding = EncodingSchema.parse(encodingRaw);
const connParams = connParamsRaw ? JSON.parse(connParamsRaw) : undefined;Both
Recommendation:
Example: const result = EncodingSchema.safeParse(encodingRaw);
if (!result.success) {
throw new errors.InvalidEncoding(encodingRaw);
}
const encoding = result.data;
let connParams: unknown;
if (connParamsRaw) {
try {
connParams = JSON.parse(connParamsRaw);
} catch (error) {
throw new errors.MalformedMessage(`Invalid connection parameters: ${error}`);
}
}🐛 Potential BugsBug 1: If no Expected behavior: Should either:
Bug 2: Inconsistent default behavior
This creates inconsistent behavior between HTTP requests and WebSocket connections. 🔒 Security ConcernsLow-severity concern: Missing URL decode validation connParamsRaw = decodeURIComponent(
protocol.substring(WS_PROTOCOL_CONN_PARAMS.length),
);While ⚡ Performance ConsiderationsNo significant performance concerns. The refactoring actually improves performance slightly by:
🧪 Test CoverageMissing test coverage:
Recommendation:
📋 Suggested Changes
Summary Rating
Overall, this is a good refactoring that improves code maintainability, but it needs stronger error handling and test coverage before merging. |
More templates
@rivetkit/actor
@rivetkit/cloudflare-workers
@rivetkit/core
@rivetkit/db
@rivetkit/framework-base
@rivetkit/next-js
@rivetkit/react
rivetkit
@rivetkit/sql-loader
@rivetkit/engine-runner
@rivetkit/engine-runner-protocol
commit: |

No description provided.