Skip to content

Commit 3f4df2c

Browse files
committed
cherry-pick(#36864): fix: initial target in codegen
1 parent b847f5e commit 3f4df2c

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

packages/recorder/src/recorder.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ export const Recorder: React.FC<RecorderProps> = ({
5252
React.useEffect(() => {
5353
if (!sources.length)
5454
return;
55-
const selectedSource = sources.find(s => s.id === selectedFileId);
55+
// When no selected file id present, pick the primary source (target language).
56+
let fileId = selectedFileId ?? sources.find(s => s.isPrimary)?.id;
57+
const selectedSource = sources.find(s => s.id === fileId);
5658
const newestSource = sources.sort((a, b) => b.timestamp - a.timestamp)[0];
5759
if (!selectedSource || newestSource.isRecorded !== selectedSource.isRecorded) {
58-
// Debugger kicked in, or recording resumed. Switch selection to the newest source.
59-
setSelectedFileId(newestSource.id);
60+
// When debugger kicks in, or recording is resumed switch the selection to the newest source.
61+
fileId = newestSource.id;
6062
}
63+
// If changes above force the selection to change, update the state.
64+
if (fileId !== selectedFileId)
65+
setSelectedFileId(fileId);
6166
}, [sources, selectedFileId]);
6267

6368
const source = React.useMemo(() => {
6469
const source = sources.find(s => s.id === selectedFileId);
65-
if (source)
66-
return source;
67-
const primarySource = sources.find(s => s.isPrimary);
68-
if (primarySource)
69-
return primarySource;
70-
return emptySource();
70+
return source ?? emptySource();
7171
}, [sources, selectedFileId]);
7272

7373
const [locator, setLocator] = React.useState('');

tests/library/inspector/inspectorTest.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export { expect } from '@playwright/test';
2828
type CLITestArgs = {
2929
recorderPageGetter: () => Promise<Page>;
3030
closeRecorder: () => Promise<void>;
31-
openRecorder: (options?: { testIdAttributeName: string }) => Promise<{ recorder: Recorder, page: Page }>;
31+
openRecorder: (options?: { testIdAttributeName?: string, language?: string }) => Promise<{ recorder: Recorder, page: Page }>;
3232
runCLI: (args: string[], options?: { autoExitWhen?: string }) => CLIMock;
3333
};
3434

@@ -87,7 +87,6 @@ export const test = contextTest.extend<CLITestArgs>({
8787
openRecorder: async ({ context, recorderPageGetter }, use) => {
8888
await use(async options => {
8989
await (context as any)._enableRecorder({
90-
language: 'javascript',
9190
mode: 'recording',
9291
...options
9392
});

tests/library/inspector/title.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ test('should update primary page URL when original primary closes', async ({
5757
`Playwright Inspector - ${server.PREFIX}/dom.html`,
5858
);
5959
});
60+
61+
test('should render primary language', async ({ openRecorder }) => {
62+
const { recorder } = await openRecorder({ language: 'python' });
63+
await recorder.setContentAndWait('');
64+
await expect(recorder.recorderPage.getByRole('combobox', { name: 'Source chooser' })).toHaveValue('python');
65+
});

0 commit comments

Comments
 (0)