Skip to content

Commit 4aad5e4

Browse files
authored
[Flight] Consistent format of virtual rsc: sources (#33706)
1 parent 453a19a commit 4aad5e4

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

packages/react-client/src/ReactFlightReplyClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ function createFakeServerFunction<A: Iterable<any>, T>(
11061106
'\n//# sourceURL=rsc://React/' +
11071107
encodeURIComponent(environmentName) +
11081108
'/' +
1109-
filename +
1109+
encodeURI(filename) +
11101110
'?s' + // We add an extra s here to distinguish from the fake stack frames
11111111
fakeServerFunctionIdx++;
11121112
code += '\n//# sourceMappingURL=' + sourceMap;

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,9 @@ describe('ReactFlight', () => {
13061306
' at file:///testing.js:42:3',
13071307
// async anon function (https://github.com/ChromeDevTools/devtools-frontend/blob/831be28facb4e85de5ee8c1acc4d98dfeda7a73b/test/unittests/front_end/panels/console/ErrorStackParser_test.ts#L130C9-L130C41)
13081308
' at async file:///testing.js:42:3',
1309+
// third-party RSC frame
1310+
// Ideally this would be a real frame produced by React not a mocked one.
1311+
' at ThirdParty (rsc://React/ThirdParty/file:///code/%5Broot%2520of%2520the%2520server%5D.js?42:1:1)',
13091312
// host component in parent stack
13101313
' at div (<anonymous>)',
13111314
...originalStackLines.slice(2),
@@ -1360,7 +1363,10 @@ describe('ReactFlight', () => {
13601363
return functionName === 'div';
13611364
}
13621365
return (
1363-
!filename.startsWith('node:') && !filename.includes('node_modules')
1366+
!filename.startsWith('node:') &&
1367+
!filename.includes('node_modules') &&
1368+
// sourceURL from an ES module in `/code/[root of the server].js`
1369+
filename !== 'file:///code/[root%20of%20the%20server].js'
13641370
);
13651371
},
13661372
});

packages/react-server/src/ReactFlightServer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ function devirtualizeURL(url: string): string {
184184
// We need to reverse it back into the original location by stripping its prefix
185185
// and suffix. We don't need the environment name because it's available on the
186186
// parent object that will contain the stack.
187-
const envIdx = url.indexOf('/', 12);
187+
const envIdx = url.indexOf('/', 'rsc://React/'.length);
188188
const suffixIdx = url.lastIndexOf('?');
189189
if (envIdx > -1 && suffixIdx > -1) {
190-
return url.slice(envIdx + 1, suffixIdx);
190+
return decodeURI(url.slice(envIdx + 1, suffixIdx));
191191
}
192192
}
193193
return url;

0 commit comments

Comments
 (0)