Skip to content

Commit 4321302

Browse files
committed
fix(rsc-mf): support alphanumeric fallback hash suffix matching
1 parent 3a11926 commit 4321302

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

tests/integration/rsc-mf/host/server/modern.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from '@modern-js/server-runtime';
55

66
const REMOTE_MANIFEST_PATH = '/static/mf-manifest.json';
7-
const EXPOSE_CHUNK_HASH_SUFFIX_PATTERN = /\.[a-f0-9]{6,}$/i;
7+
const EXPOSE_CHUNK_HASH_SUFFIX_PATTERN = /\.[a-z0-9]{6,}$/i;
88

99
interface RemoteManifestAssetEntry {
1010
assets?: {

tests/integration/rsc-mf/tests/modernServerConfig.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,68 @@ describe('rsc-mf host modern.server middleware contracts', () => {
651651
await expect(context.res?.text()).resolves.toBe('query-fallback-hit');
652652
});
653653

654+
it('matches fallback chunks when manifest hash suffix includes non-hex characters', async () => {
655+
const handler = getProxyMiddlewareHandler();
656+
const next = jest.fn(async (): Promise<void> => undefined);
657+
const fetchMock = installFetchMock(
658+
jest
659+
.fn()
660+
.mockResolvedValueOnce(new Response('not-found', { status: 404 }))
661+
.mockResolvedValueOnce(
662+
new Response(
663+
JSON.stringify({
664+
exposes: [
665+
{
666+
assets: {
667+
js: {
668+
sync: [
669+
'static/js/async/__federation_expose_RemoteServerCard.a1b2c3x9.js',
670+
],
671+
async: [],
672+
},
673+
css: {
674+
sync: [],
675+
async: [],
676+
},
677+
},
678+
},
679+
],
680+
}),
681+
{
682+
status: 200,
683+
headers: {
684+
'content-type': 'application/json',
685+
},
686+
},
687+
),
688+
)
689+
.mockResolvedValueOnce(
690+
new Response('non-hex-hash-fallback-hit', {
691+
status: 200,
692+
headers: {
693+
'content-type': 'application/javascript',
694+
},
695+
}),
696+
),
697+
);
698+
const context: { req: { url: string }; res?: Response } = {
699+
req: {
700+
url: 'http://127.0.0.1:3007/static/js/async/__federation_expose_RemoteServerCard.js',
701+
},
702+
};
703+
704+
await withRemotePort('3999', () => handler(context, next));
705+
706+
expect(fetchMock).toHaveBeenNthCalledWith(
707+
3,
708+
'http://127.0.0.1:3999/static/js/async/__federation_expose_RemoteServerCard.a1b2c3x9.js',
709+
);
710+
expect(next).not.toHaveBeenCalled();
711+
await expect(context.res?.text()).resolves.toBe(
712+
'non-hex-hash-fallback-hit',
713+
);
714+
});
715+
654716
it('resolves fallback asset paths from manifest async asset arrays', async () => {
655717
const handler = getProxyMiddlewareHandler();
656718
const next = jest.fn(async (): Promise<void> => undefined);

0 commit comments

Comments
 (0)