From 565282cfdd092aeaa2ab6c3834eec86fded5aed0 Mon Sep 17 00:00:00 2001 From: "wangyiming.fe" Date: Tue, 7 Nov 2023 18:37:13 +0800 Subject: [PATCH 1/3] fix: even if the page component exists, we should not keep the page component --- .changeset/wise-eggs-breathe.md | 6 +++ .../app-tools/src/analyze/nestedRoutes.ts | 4 +- .../__snapshots__/nestedRoutes.test.ts.snap | 44 +++++-------------- .../tests/analyze/nestedRoutes.test.ts | 13 ++---- 4 files changed, 20 insertions(+), 47 deletions(-) create mode 100644 .changeset/wise-eggs-breathe.md diff --git a/.changeset/wise-eggs-breathe.md b/.changeset/wise-eggs-breathe.md new file mode 100644 index 000000000000..5ff60f45919a --- /dev/null +++ b/.changeset/wise-eggs-breathe.md @@ -0,0 +1,6 @@ +--- +'@modern-js/app-tools': patch +--- + +fix: Even if the page component exists, we should not keep the page component +fix: 即使页面组件存在,也不应该保留 page component diff --git a/packages/solutions/app-tools/src/analyze/nestedRoutes.ts b/packages/solutions/app-tools/src/analyze/nestedRoutes.ts index 6e07b94d31d5..7765bd0172aa 100644 --- a/packages/solutions/app-tools/src/analyze/nestedRoutes.ts +++ b/packages/solutions/app-tools/src/analyze/nestedRoutes.ts @@ -78,14 +78,12 @@ export const optimizeRoute = ( } const { children } = routeTree; - const hasPage = children.some(child => child.index); if ( !routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && - !routeTree.clientData && - !hasPage + !routeTree.clientData ) { const newRoutes = children.map(child => { const routePath = `${routeTree.path ? routeTree.path : ''}${ diff --git a/packages/solutions/app-tools/tests/analyze/__snapshots__/nestedRoutes.test.ts.snap b/packages/solutions/app-tools/tests/analyze/__snapshots__/nestedRoutes.test.ts.snap index c8ccce82bd27..036599af60fb 100644 --- a/packages/solutions/app-tools/tests/analyze/__snapshots__/nestedRoutes.test.ts.snap +++ b/packages/solutions/app-tools/tests/analyze/__snapshots__/nestedRoutes.test.ts.snap @@ -12,17 +12,9 @@ exports[`nested routes walk 1`] = ` "_component": "@_modern_js_src/__auth/__shop/layout.tsx", "children": [ { - "children": [ - { - "_component": "@_modern_js_src/__auth/__shop/item/page.tsx", - "children": undefined, - "id": "__auth/__shop/item/page", - "index": true, - "type": "nested", - }, - ], - "id": "__auth/__shop/item/layout", - "isRoot": false, + "_component": "@_modern_js_src/__auth/__shop/item/page.tsx", + "children": undefined, + "id": "__auth/__shop/item/page", "path": "item", "type": "nested", }, @@ -32,17 +24,9 @@ exports[`nested routes walk 1`] = ` "type": "nested", }, { - "children": [ - { - "_component": "@_modern_js_src/__auth/login/page.tsx", - "children": undefined, - "id": "__auth/login/page", - "index": true, - "type": "nested", - }, - ], - "id": "__auth/login/layout", - "isRoot": false, + "_component": "@_modern_js_src/__auth/login/page.tsx", + "children": undefined, + "id": "__auth/login/page", "path": "login", "type": "nested", }, @@ -67,18 +51,10 @@ exports[`nested routes walk 1`] = ` "type": "nested", }, { - "children": [ - { - "_component": "@_modern_js_src/user/[id]/page.tsx", - "children": undefined, - "data": "/tests/analyze/fixtures/nested-routes/user/[id]/page.data.ts", - "id": "user/(id)/page", - "index": true, - "type": "nested", - }, - ], - "id": "user/(id)/layout", - "isRoot": false, + "_component": "@_modern_js_src/user/[id]/page.tsx", + "children": undefined, + "data": "/tests/analyze/fixtures/nested-routes/user/[id]/page.data.ts", + "id": "user/(id)/page", "path": ":id", "type": "nested", }, diff --git a/packages/solutions/app-tools/tests/analyze/nestedRoutes.test.ts b/packages/solutions/app-tools/tests/analyze/nestedRoutes.test.ts index 5764ac412acc..5a50060ea07c 100644 --- a/packages/solutions/app-tools/tests/analyze/nestedRoutes.test.ts +++ b/packages/solutions/app-tools/tests/analyze/nestedRoutes.test.ts @@ -163,17 +163,10 @@ describe('nested routes', () => { _component: 'layoutB', children: [ { - id: 'c', - type: 'nested', + id: 'd', path: 'c', - children: [ - { - id: 'd', - type: 'nested', - _component: 'pageD', - index: true, - }, - ], + _component: 'pageD', + type: 'nested', }, ], }, From b211591e9f9e7aa74abafc6f9dc25b25336f2dbf Mon Sep 17 00:00:00 2001 From: "wangyiming.fe" Date: Wed, 8 Nov 2023 10:38:37 +0800 Subject: [PATCH 2/3] fix: even if the page component exists, we should not keep the layout component --- .changeset/wise-eggs-breathe.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/wise-eggs-breathe.md b/.changeset/wise-eggs-breathe.md index 5ff60f45919a..17e48ea19146 100644 --- a/.changeset/wise-eggs-breathe.md +++ b/.changeset/wise-eggs-breathe.md @@ -2,5 +2,5 @@ '@modern-js/app-tools': patch --- -fix: Even if the page component exists, we should not keep the page component -fix: 即使页面组件存在,也不应该保留 page component +fix: Even if the page component exists, we should not keep the layout component +fix: 即使页面组件存在,也不应该保留 layout component From fb9eb6abfce4293586e8a2a5a4b8cbfd218726ed Mon Sep 17 00:00:00 2001 From: "wangyiming.fe" Date: Wed, 8 Nov 2023 10:40:06 +0800 Subject: [PATCH 3/3] fix: even if the page component exists, we should not create the empty layout component --- .changeset/wise-eggs-breathe.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/wise-eggs-breathe.md b/.changeset/wise-eggs-breathe.md index 17e48ea19146..7909ba44ff3a 100644 --- a/.changeset/wise-eggs-breathe.md +++ b/.changeset/wise-eggs-breathe.md @@ -2,5 +2,5 @@ '@modern-js/app-tools': patch --- -fix: Even if the page component exists, we should not keep the layout component -fix: 即使页面组件存在,也不应该保留 layout component +fix: Even if the page component exists, we should not create the empty layout component +fix: 即使页面组件存在,也不应该创建一个空的 layout component