fix(server-runtime): preserve explicit empty data destinations#1635
Conversation
⏳ Approval required for deploying to Cloudflare Workers (Preview) for stage-web.
Hey, maintainers, kindly take some time to review and approve this deployment when you are available. Thank you! 🙏 |
There was a problem hiding this comment.
Code Review
This pull request updates the collectDestinations function to correctly handle explicit empty destination lists as overrides and adds a corresponding test case. A review comment identifies a potential runtime error when using the in operator on primitive types and suggests a safer check.
|
|
||
| const data = event.data as { destinations?: Array<string | RouteTargetExpression> } | undefined | ||
| if (data?.destinations?.length) { | ||
| if (data && 'destinations' in data) { |
There was a problem hiding this comment.
The in operator will throw a TypeError if data is a primitive value (such as a string or boolean). Since event.data can be any type depending on the specific event, it is safer to verify that data is a non-null object before performing this check to avoid potential runtime crashes.
| if (data && 'destinations' in data) { | |
| if (data && typeof data === 'object' && 'destinations' in data) { |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2eef8fb8b8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| const data = event.data as { destinations?: Array<string | RouteTargetExpression> } | undefined | ||
| if (data?.destinations?.length) { | ||
| if (data && 'destinations' in data) { |
There was a problem hiding this comment.
Guard destination lookup against primitive payloads
collectDestinations now uses data && 'destinations' in data, but event.data is only parsed/cast (not schema-validated) before routing, so malformed events like {"type":"unknown","data":"x"} can reach this path and make the in operator throw a TypeError on a primitive. That turns an otherwise ignorable invalid message into an uncaught runtime failure during message handling; the previous optional-chaining check did not throw in this scenario.
Useful? React with 👍 / 👎.
|
@copilot resolve the merge conflicts in this pull request |
|
Rebased this branch onto current |
2f8564e to
d3677d0
Compare
|
Follow-up update on the current branch head I narrowed the destination override typing so Focused verification on the refreshed head:
|
c4be8a3 to
72f7562
Compare
Summary
Validation
This is a follow-up to the routing edge case discussed on #1621.