Conversation
[email protected] used `new Proxy(event.stopPropagation, ...)` which throws on React Native with Hermes because the polyfilled Event does not define stopPropagation as a function. [email protected] replaced the Proxy approach with a simple function wrapper, resolving the crash. Agent-Logs-Url: https://github.com/JavanPoirier/msw/sessions/30b4db7a-5277-4e4b-9b2a-08fe9e43c2b2
…dler stopPropagation safety Agent-Logs-Url: https://github.com/JavanPoirier/msw/sessions/4f5d7bb2-572d-4cae-88d4-69b8e14d9052
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughBumps runtime dependency Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/core/handlers/WebSocketHandler.ts (1)
197-199:⚠️ Potential issue | 🟠 MajorGuard
stopImmediatePropagationfor Hermes-like events.Line 198 can still throw when
stopImmediatePropagationis missing (same class of polyfill issue this PR addresses), once propagation has already been marked by another handler.Safe runtime-compatible fix
if (propagationStoppedAt && handler.id !== propagationStoppedAt) { - event.stopImmediatePropagation() + Reflect.get(event, 'stopImmediatePropagation')?.call(event) return }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/core/handlers/WebSocketHandler.ts` around lines 197 - 199, The code calls event.stopImmediatePropagation() without ensuring it exists, which can throw for Hermes-like/polyfilled events; update the guard inside the propagation check (the block using propagationStoppedAt and handler.id) to first verify that event.stopImmediatePropagation is a function (e.g., typeof event.stopImmediatePropagation === "function") before calling it so handlers that mark propagation won't cause runtime errors in environments lacking that method.
🧹 Nitpick comments (1)
src/core/handlers/WebSocketHandler.test.ts (1)
21-30: Strengthen this assertion to detect patch regressions.On Line 29, callable
event.stopPropagationis true even without patching. Consider also asserting the patched side effect (kPropagationStoppedAt) after invokingevent.stopPropagation().Suggested test tightening
const listener = createStopPropagationListener(handler) listener(event) - // stopPropagation should be patched and still callable. - expect(() => event.stopPropagation()).not.toThrow() + expect(() => event.stopPropagation()).not.toThrow() + expect(Reflect.get(event, 'kPropagationStoppedAt')).toBe(handler.id)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/core/handlers/WebSocketHandler.test.ts` around lines 21 - 30, The test currently only checks that event.stopPropagation() is callable, which can pass without the patch; update the test using WebSocketHandler and createStopPropagationListener so after calling event.stopPropagation() you also assert the patched side-effect: the event has the kPropagationStoppedAt property set (e.g., is defined and is a number or true) to verify the patch applied by createStopPropagationListener; use the same Event instance and symbol name kPropagationStoppedAt to locate and assert the added property.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/core/handlers/WebSocketHandler.ts`:
- Around line 197-199: The code calls event.stopImmediatePropagation() without
ensuring it exists, which can throw for Hermes-like/polyfilled events; update
the guard inside the propagation check (the block using propagationStoppedAt and
handler.id) to first verify that event.stopImmediatePropagation is a function
(e.g., typeof event.stopImmediatePropagation === "function") before calling it
so handlers that mark propagation won't cause runtime errors in environments
lacking that method.
---
Nitpick comments:
In `@src/core/handlers/WebSocketHandler.test.ts`:
- Around line 21-30: The test currently only checks that event.stopPropagation()
is callable, which can pass without the patch; update the test using
WebSocketHandler and createStopPropagationListener so after calling
event.stopPropagation() you also assert the patched side-effect: the event has
the kPropagationStoppedAt property set (e.g., is defined and is a number or
true) to verify the patch applied by createStopPropagationListener; use the same
Event instance and symbol name kPropagationStoppedAt to locate and assert the
added property.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5ba17112-f2ea-40ec-ba8b-a00949d90ed7
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
package.jsonsrc/core/handlers/WebSocketHandler.test.tssrc/core/handlers/WebSocketHandler.tstest/native/hermes-event-polyfill.native.test.ts
…then test assertion Agent-Logs-Url: https://github.com/JavanPoirier/msw/sessions/95bfdf4f-fbf4-40d1-85be-62805e355900 Co-authored-by: JavanPoirier <[email protected]>
55ea7c7 to
cf79863
Compare
|
Hi, @JavanPoirier. Appreciate the detailed explanation of the issue. But I have a serious concern with the proposed solution. You are suggesting we tailor to a broken polyfill. There is nothing wrong relying on I am open to discussion on this, but at its current state, I cannot accept these suggestions. |
v2.13.2 breaks RN mocking. Maybe freeze the
rettimedep, as it is susceptible to breaking changes?On React Native with Hermes, polyfilled Event doesn't define stopPropagation on its prototype. MSW's WebSocketHandler wraps it with new Proxy(event.stopPropagation, ...), which throws TypeError: new Proxy target must be an Object when stopPropagation is undefined. This is the same class of bug that was fixed in [email protected].
Changes
test/native/hermes-event-polyfill.native.test.ts — Regression test that stubs a minimal Hermes-like Event/MessageEvent (no stopPropagation on prototype) and verifies setupServer() from msw/native doesn't crash. Runs in the existing test:native vitest suite with no new dependencies.
src/core/handlers/WebSocketHandler.test.ts — Unit tests for createStopPropagationListener covering both the Hermes case (undefined stopPropagation) and standard Events.