From 4a4c122f509a45565dc9c4f510a7bf8a271c1500 Mon Sep 17 00:00:00 2001 From: RajeshKumar11 Date: Sat, 8 Aug 2026 14:43:56 +0530 Subject: [PATCH] fix(swc): avoid treating Pages Router sitemap and robots routes as app entries --- .../src/transforms/react_server_components.rs | 16 +++++++++++++++- .../pages-sitemap-getstaticprops/index.test.ts | 14 ++++++++++++++ .../pages/sitemap.js | 11 +++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/e2e/pages-sitemap-getstaticprops/index.test.ts create mode 100644 test/e2e/pages-sitemap-getstaticprops/pages/sitemap.js diff --git a/crates/next-custom-transforms/src/transforms/react_server_components.rs b/crates/next-custom-transforms/src/transforms/react_server_components.rs index f82d0af79e5a..3290da360c5a 100644 --- a/crates/next-custom-transforms/src/transforms/react_server_components.rs +++ b/crates/next-custom-transforms/src/transforms/react_server_components.rs @@ -910,7 +910,21 @@ impl ReactServerComponentValidator { r"[\\/](page|layout|route|icon\d?|apple-icon\d?|opengraph-image\d?|twitter-image\d?|sitemap|robots|manifest)\.{ext_pattern}$", )) .unwrap(); - let is_app_entry = re.is_match(&self.filepath); + let is_in_app_dir = self + .app_dir + .as_ref() + .and_then(|app_dir| app_dir.to_str()) + .map_or(false, |app_dir| self.filepath.starts_with(app_dir)); + + let is_app_entry = if is_in_app_dir { + re.is_match(&self.filepath) + } else if self.app_dir.is_none() { + let app_core_re = + Regex::new(&format!(r"[\\/](page|layout|route)\.{ext_pattern}$")).unwrap(); + app_core_re.is_match(&self.filepath) + } else { + false + }; if is_app_entry { let mut possibly_invalid_exports: FxIndexMap = diff --git a/test/e2e/pages-sitemap-getstaticprops/index.test.ts b/test/e2e/pages-sitemap-getstaticprops/index.test.ts new file mode 100644 index 000000000000..1c2a09e14b99 --- /dev/null +++ b/test/e2e/pages-sitemap-getstaticprops/index.test.ts @@ -0,0 +1,14 @@ +import { nextTestSetup } from 'e2e-utils' + +describe('pages sitemap with getStaticProps', () => { + const { next } = nextTestSetup({ + files: __dirname, + }) + + it('should render sitemap page with getStaticProps successfully', async () => { + const browser = await next.browser('/sitemap') + expect(await browser.elementById('message').text()).toBe( + 'Hello from sitemap getStaticProps' + ) + }) +}) diff --git a/test/e2e/pages-sitemap-getstaticprops/pages/sitemap.js b/test/e2e/pages-sitemap-getstaticprops/pages/sitemap.js new file mode 100644 index 000000000000..aa3a75da5812 --- /dev/null +++ b/test/e2e/pages-sitemap-getstaticprops/pages/sitemap.js @@ -0,0 +1,11 @@ +export async function getStaticProps() { + return { + props: { + message: 'Hello from sitemap getStaticProps', + }, + } +} + +export default function Sitemap({ message }) { + return

{message}

+}