Skip to content

Commit c220479

Browse files
committed
refactor(rsc-mf): model effective remote action map keys
1 parent f02e2cf commit c220479

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

tests/integration/rsc-mf/host/src/server-component-root/App.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,23 @@ const App = () => {
9696
const remoteActionIdToHostProxyActionId = Object.fromEntries(
9797
remoteActionIdToHostProxyActionEntries,
9898
);
99+
const remoteActionIdMapKeyCount = Object.keys(
100+
remoteActionIdToHostProxyActionId,
101+
).length;
99102
const remoteActionIdMapKey = JSON.stringify(
100-
remoteActionIdToHostProxyActionEntries,
103+
Object.entries(remoteActionIdToHostProxyActionId).sort(([left], [right]) =>
104+
left.localeCompare(right),
105+
),
101106
);
102107
const remoteActionIdMapEntryCount =
103108
remoteActionIdToHostProxyActionEntries.length;
104109
const mappedHostProxyActionIds = Array.from(
105-
new Set(remoteActionIdToHostProxyActionEntries.map(([, hostId]) => hostId)),
110+
new Set(Object.values(remoteActionIdToHostProxyActionId)),
106111
).sort();
107112
const doesMappingCoverAllHostProxyActions =
108-
mappedHostProxyActionIds.length === uniqueHostProxyActionIds.length &&
109-
mappedHostProxyActionIds.every(
110-
(actionId, index) => actionId === uniqueHostProxyActionIds[index],
113+
mappedHostProxyActionIds.length <= uniqueHostProxyActionIds.length &&
114+
mappedHostProxyActionIds.every(actionId =>
115+
uniqueHostProxyActionIds.includes(actionId),
111116
);
112117

113118
const remoteServerOnlyInfo = getServerOnlyInfo();
@@ -141,6 +146,7 @@ const App = () => {
141146
<p className="host-proxy-map-entry-count">
142147
{remoteActionIdMapEntryCount}
143148
</p>
149+
<p className="host-proxy-map-key-count">{remoteActionIdMapKeyCount}</p>
144150
<p className="host-mapped-proxy-action-ids">
145151
{mappedHostProxyActionIds.join(',')}
146152
</p>

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ async function renderRemoteRscIntoHost({ hostPort, page }: TestContext) {
6666
expect(html).toContain('host-remote-bundled-meta-kind');
6767
expect(html).toContain('host-proxy-action-id-count');
6868
expect(html).toContain('host-proxy-map-entry-count');
69+
expect(html).toContain('host-proxy-map-key-count');
6970
expect(html).toContain('host-mapped-proxy-action-ids');
7071
expect(html).toContain('host-proxy-map-covers-all');
7172
expect(html).toContain('host-proxy-action-ids');
@@ -125,17 +126,22 @@ async function renderRemoteRscIntoHost({ hostPort, page }: TestContext) {
125126
el => el.textContent?.trim(),
126127
);
127128
expect(hostProxyMapEntryCount).toBe('8');
129+
const hostProxyMapKeyCount = await page.$eval(
130+
'.host-proxy-map-key-count',
131+
el => el.textContent?.trim(),
132+
);
133+
expect(Number(hostProxyMapKeyCount)).toBeGreaterThan(0);
134+
expect(Number(hostProxyMapKeyCount)).toBeLessThanOrEqual(
135+
Number(hostProxyMapEntryCount),
136+
);
128137
const hostMappedProxyActionIds = await page.$eval(
129138
'.host-mapped-proxy-action-ids',
130139
el => el.textContent?.trim(),
131140
);
132141
const hostMappedProxyActionIdList = hostMappedProxyActionIds
133142
?.split(',')
134143
.filter(Boolean) as string[];
135-
expect(hostMappedProxyActionIdList.length).toBe(8);
136-
expect(hostMappedProxyActionIdList.length).toBe(
137-
Number(hostProxyMapEntryCount),
138-
);
144+
expect(hostMappedProxyActionIdList.length).toBe(Number(hostProxyMapKeyCount));
139145
const hostProxyMapCoversAll = await page.$eval(
140146
'.host-proxy-map-covers-all',
141147
el => el.textContent?.trim(),
@@ -156,8 +162,8 @@ async function renderRemoteRscIntoHost({ hostPort, page }: TestContext) {
156162
const sortedHostProxyActionIds = [...hostProxyActionIdList].sort();
157163
const sortedMappedProxyActionIds = [...hostMappedProxyActionIdList].sort();
158164
expect(
159-
sortedHostProxyActionIds.every(
160-
(id, index) => id === sortedMappedProxyActionIds[index],
165+
sortedMappedProxyActionIds.every(mappedId =>
166+
sortedHostProxyActionIds.includes(mappedId),
161167
),
162168
).toBe(true);
163169
const hostDirectProxyActionIds = await page.$eval(

0 commit comments

Comments
 (0)