From 06fcc8f380c6a905c7bc18d94453f623cf8cbc81 Mon Sep 17 00:00:00 2001 From: Ian Duvall Date: Thu, 9 Oct 2025 12:02:55 -0700 Subject: [PATCH] [playground] Fix syntax error from crashing the Compiler playground (#34623) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fixes a syntax error causing the Compiler playground to crash. Resolves https://github.com/facebook/react/issues/34622. ## How did you test this change? Tested locally and added a test. Screenshot 2025-09-27 at 8 13 07 AM --- .../playground/__tests__/e2e/page.spec.ts | 30 +++++++++++++++++++ compiler/apps/playground/lib/compilation.ts | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/compiler/apps/playground/__tests__/e2e/page.spec.ts b/compiler/apps/playground/__tests__/e2e/page.spec.ts index 94abe40eeb864..8ad9f122aab34 100644 --- a/compiler/apps/playground/__tests__/e2e/page.spec.ts +++ b/compiler/apps/playground/__tests__/e2e/page.spec.ts @@ -314,6 +314,36 @@ test('disableMemoizationForDebugging flag works as expected', async ({ expect(output).toMatchSnapshot('disableMemoizationForDebugging-output.txt'); }); +test('error is displayed when source has syntax error', async ({page}) => { + const syntaxErrorSource = `function TestComponent(props) { + const oops = props. + return ( + <>{oops} + ); +}`; + const store: Store = { + source: syntaxErrorSource, + config: defaultConfig, + showInternals: false, + }; + const hash = encodeStore(store); + await page.goto(`/#${hash}`); + await page.waitForFunction(isMonacoLoaded); + await expandConfigs(page); + await page.screenshot({ + fullPage: true, + path: 'test-results/08-source-syntax-error.png', + }); + + const text = + (await page.locator('.monaco-editor-output').allInnerTexts()) ?? []; + const output = text.join(''); + + expect(output.replace(/\s+/g, ' ')).toContain( + 'Expected identifier to be defined before being used', + ); +}); + TEST_CASE_INPUTS.forEach((t, idx) => test(`playground compiles: ${t.name}`, async ({page}) => { const store: Store = { diff --git a/compiler/apps/playground/lib/compilation.ts b/compiler/apps/playground/lib/compilation.ts index 10bf0164c0e77..f668c05dde2a6 100644 --- a/compiler/apps/playground/lib/compilation.ts +++ b/compiler/apps/playground/lib/compilation.ts @@ -297,7 +297,7 @@ export function compile( if (!error.hasErrors() && otherErrors.length !== 0) { otherErrors.forEach(e => error.details.push(e)); } - if (error.hasErrors()) { + if (error.hasErrors() || !transformOutput) { return [{kind: 'err', results, error}, language, baseOpts]; } return [