Replies: 1 comment 7 replies
-
Hi, @vitalets. Thanks for raising this. RSC still use regular HTTP to send their payloads. There's nothing needed on MSW's side for you to intercept and mock RSC payloads! Intercept the request and mock the response (the payload). See how React encodes the payload to produce the same values for your app to decode properly. Here's an extremely crude representation of what I mean: http.get('/path', () => {
return HttpResponse.text(decodePayload(payload))
}) |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Scope
Adds a new behavior
Compatibility
Feature description
While I'm closely tracking the progress of App Router support in #1644, I have a proposal for solving that from another side:
Can MSW be adopted to mock React Server Component (RSC) payload?
I know that RSC is a binary format, but looking on RSC requests in devtools I see the following:
Sometimes there are full JSON stringified values, that I use in my components and that I would like to mock.
I've tried to intercept such request and make plain string replacement -> values were mocked.
I've also checked server action requests, the response is also RSC with similar structure. For example, if server action throws an error, the status code is 500 and the body is:
Service worker could intercept that request and return mock with status 500 and custom error message. It allows to test such scenarios in components.
There is a RSC parser that could give more details on structure and what can be mocked in RSC payload.
In terms of MSW, I think of a separate RSC namespace like existing
http
andgraphql
. Pseudocode:What do you think?
Beta Was this translation helpful? Give feedback.
All reactions