Skip to content

refactor(routes): quebra App.tsx (336L→67L) em src/routes/ por área (F1-1.x)#119

Merged
adm01-debug merged 2 commits into
mainfrom
refactor/app-tsx-split
May 9, 2026
Merged

refactor(routes): quebra App.tsx (336L→67L) em src/routes/ por área (F1-1.x)#119
adm01-debug merged 2 commits into
mainfrom
refactor/app-tsx-split

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

@adm01-debug adm01-debug commented May 9, 2026

Onda B do plano de auditoria F1

Refatora src/App.tsx que tinha 336 linhas, 26 imports e 96 rotas em um único arquivo — bagunça crítica identificada na auditoria como item #6 do Top 20.

📦 Mudanças

Antes Depois
src/App.tsx 336 linhas src/App.tsx 67 linhas (-80%)
96 rotas em 1 arquivo 96 rotas em 9 arquivos por área
26 imports no topo 22 imports (só providers e wrappers)
RoutePrefetcher inline src/routes/RoutePrefetcher.tsx
RouteSuspense inline src/routes/AppRoutes.tsx (extraído)

🗂 Estrutura nova

src/App.tsx                       67L  ← só providers e estrutura
src/routes/
├── AppRoutes.tsx                 49L  ← orquestrador <Routes>
├── lazy-pages.ts                129L  ← todos lazyWithRetry centralizados
├── RoutePrefetcher.tsx           41L  ← helper de prefetch
├── public-routes.tsx             17L  ← /login, /reset, /unauthorized (4)
├── product-routes.tsx            35L  ← produtos, filtros, novidades (12)
├── quote-routes.tsx              28L  ← orçamentos (8)
├── admin-routes.tsx             126L  ← /admin/* + DevRoute (33)
├── tools-routes.tsx              45L  ← simulador, mockup, BI (17)
└── client-routes.tsx             50L  ← home, clientes, redirects, 404 (12)

✅ Validação de equivalência

  • 93 paths únicos antigos = 93 paths únicos novos (diff /tmp/old-paths /tmp/new-paths = vazio)
  • Ordem de matching preservada (homeAndClientRoutes mantém o catch-all * mounted last)
  • <AdminRoute /> e <DevRoute /> permanecem aninhados corretamente
  • <DeprecatedRoute /> mantida nos 4 paths legados (performance, performance-comercial, comissoes 2x)
  • Todos os Navigate replace preservados
  • @/pages/... em vez de ./pages/... para path absoluto consistente (resolve via tsconfig)

🔒 Arquivos NÃO mexidos

  • src/pages/**/* — nenhum page foi movido. Baseline TS intacto.
  • src/components/layout/{Protected,Admin,Dev,Deprecated}Route.tsx — guards permanecem como antes.
  • src/lib/lazyWithRetry.ts — helper preservado.
  • src/App.css — estilos preservados.

💡 Por que importa

Antes, mexer numa rota exigia rolar até linha ~250 do App.tsx num arquivo gigante com 7 Providers aninhados. Agora cada área é um arquivo de até 130 linhas com escopo claro.

Adicionar uma rota nova passa a ser:

  1. Adicionar entry em lazy-pages.ts
  2. Adicionar <Route> no arquivo da área correspondente

Sem mais tocar o App.tsx, sem mais conflitos de merge no arquivo central quando 2 PRs adicionam rotas em áreas diferentes.

⚠️ Risk

🟡 Médio. Reorganização estrutural extensa, mas:

  • Zero mudança de comportamento (paths idênticos, ordem preservada)
  • Sem tocar nenhum page component
  • Equivalência verificada via diff de paths
  • CI completo (tsc + ESLint + build + smoke + ref-warnings) valida tudo

📋 Test plan

  • 93 paths únicos antigos = 93 novos (diff vazio)
  • App.tsx 336L → 67L (-80%)
  • Todos os 9 arquivos novos com header de propósito documentado
  • AdminRoute + DevRoute nesting preservado
  • CI verde (tsc + ESLint + build)
  • CodeRabbit OK
  • Vercel preview funciona (todas as rotas navegáveis)

Summary by CodeRabbit

  • Refactor

    • Reorganizou a estrutura de rotas em módulos separados, simplificando o arquivo principal da aplicação.
    • Moveu a lógica de prefetch para um componente dedicado.
  • Novos Recursos

    • Adicionou conjuntos de rotas para produtos, orçamentos, ferramentas, clientes e área administrativa.
    • Centralizou carregamento preguiçoso de páginas para melhorar desempenho e manutenção.
  • Chore

    • Atualizou testes de verificação para inspecionar todas as rotas definidas.

Review Change Stack

…F1-1.x)

## Onda B do plano de auditoria F1

Refatora `src/App.tsx` que tinha **336 linhas, 26 imports e 96 rotas em
um único arquivo** — bagunça crítica identificada na auditoria como item
#6 do Top 20.

## Mudanças

| Antes | Depois |
|---|---|
| `src/App.tsx` 336 linhas | `src/App.tsx` **67 linhas (-80%)** |
| 96 rotas em 1 arquivo | 96 rotas em 9 arquivos por área |
| 26 imports no topo | 22 imports (só providers e wrappers) |
| RoutePrefetcher inline | `src/routes/RoutePrefetcher.tsx` |
| RouteSuspense inline | `src/routes/AppRoutes.tsx` (extraído) |

## Estrutura nova

```
src/App.tsx                       67L  ← só providers e estrutura
src/routes/
├── AppRoutes.tsx                 49L  ← orquestrador <Routes>
├── lazy-pages.ts                129L  ← todos lazyWithRetry centralizados
├── RoutePrefetcher.tsx           41L  ← helper de prefetch
├── public-routes.tsx             17L  ← /login, /reset, /unauthorized (4)
├── product-routes.tsx            35L  ← produtos, filtros, novidades (12)
├── quote-routes.tsx              28L  ← orçamentos (8)
├── admin-routes.tsx             126L  ← /admin/* + DevRoute (33)
├── tools-routes.tsx              45L  ← simulador, mockup, BI (17)
└── client-routes.tsx             50L  ← home, clientes, redirects, 404 (12)
```

## Validação de equivalência

- ✅ **93 paths únicos antigos = 93 paths únicos novos** (diff vazio)
- ✅ Ordem de matching preservada (`homeAndClientRoutes` mantém o catch-all
  `*` mounted last)
- ✅ `<AdminRoute />` e `<DevRoute />` permanecem aninhados corretamente
- ✅ `<DeprecatedRoute />` mantida nos 4 paths legados
- ✅ Todos os `Navigate replace` preservados
- ✅ `@/pages/...` em vez de `./pages/...` para path absoluto consistente

## Arquivos NÃO mexidos

- `src/pages/**/*` — nenhum page foi movido. **Baseline TS intacto.**
- `src/components/layout/{Protected,Admin,Dev,Deprecated}Route.tsx` —
  guards permanecem como antes.
- `src/lib/lazyWithRetry.ts` — helper preservado.

## Por que importa

Antes, mexer numa rota exigia rolar até linha ~250 do App.tsx num arquivo
gigante com 7 Providers aninhados. Agora cada área é um arquivo de até
130 linhas com escopo claro.

Adicionar uma rota nova passa a ser:
1. Adicionar entry em `lazy-pages.ts`
2. Adicionar `<Route>` no arquivo da área correspondente

Sem mais tocar o App.tsx, sem mais conflitos de merge no arquivo central
quando 2 PRs adicionam rotas em áreas diferentes.

## Risk

🟡 **Médio**. Reorganização estrutural extensa, mas:
- Zero mudança de comportamento (paths idênticos, ordem preservada)
- Sem tocar nenhum page component
- Equivalência verificada via diff de paths

## Test plan

- [x] 93 paths únicos antigos = 93 novos (diff /tmp/old vs /tmp/new vazio)
- [x] App.tsx 336L → 67L
- [x] Todos os 9 arquivos novos com header de propósito documentado
- [ ] CI verde (tsc, ESLint, build, smoke tests, ref-warning gates)
- [ ] CodeRabbit OK
- [ ] Vercel preview funciona (todas as rotas navegáveis)
Copilot AI review requested due to automatic review settings May 9, 2026 18:42
@vercel
Copy link
Copy Markdown

vercel Bot commented May 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
promo-gifts Ready Ready Preview, Comment May 9, 2026 6:47pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

Walkthrough

Refactor de roteamento que extrai ~279 linhas de definições inline de src/App.tsx para módulos especializados em src/routes/. Cria um registro centralizado de lazy pages, agrupa rotas por domínio (público, produtos, cotações, admin, ferramentas, clientes), implementa precarregamento inteligente e compõe a árvore final de rotas via AppRoutes.

Changes

Consolidação do Sistema de Roteamento

Layer / File(s) Summary
Registro Centralizado de Lazy Pages
src/routes/lazy-pages.ts
75 componentes de página agrupados por contexto (auth, produtos, cotações, admin, ferramentas, clientes, sistema) são lazy-loaded via lazyWithRetry, criando single source of truth para imports dinâmicos.
Rotas Públicas
src/routes/public-routes.tsx
Quatro rotas para fluxos não autenticados: /login, /reset-password, /auth/callback, /unauthorized.
Rotas de Produtos
src/routes/product-routes.tsx
Rotas /filtros, /produtos, /novidades, /replenishments, /favoritos, /comparar, /colecoes com parâmetros dinâmicos (:id, :cartId). Inclui redirect /produto/produtos.
Rotas de Cotações
src/routes/quote-routes.tsx
Cinco rotas sob /orcamentos para listar, dashboard, kanban, templates, builder (criar/editar) e visualização por :id.
Rotas de Ferramentas
src/routes/tools-routes.tsx
Rotas para simulador, preços, estoque, busca avançada, kit builder, mockup, histórico, magic-up, BI e comparador. Inclui dois Navigate redirects para aliases legadas (/kit-builder, mockup paths).
Rotas de Home e Clientes
src/routes/client-routes.tsx
Home (/, /dashboard), admin temas autenticado, múltiplas navegações internas, deprecated /comissoes via DeprecatedRoute, CRM (/clientes, /clientes/:id), legacy /perfil redirect, catch-all * para NotFound.
Rotas Admin e Dev
src/routes/admin-routes.tsx
Redirect /admin/admin/usuarios. Rotas para usuários, cadastros, produtos, segurança, workflows, design tokens, temas, kit templates. Nested <DevRoute> para páginas técnicas/QA (prompts IA, telemetria, rate-limit, external-db, challenges, migrações, auditoria). Legacy routes via DeprecatedRoute.
Composição de Roteamento
src/routes/AppRoutes.tsx
Introduz RouteSuspense (location-aware skeleton) e compõe árvore final: publicRoutes fora de autenticação, depois ProtectedRoute contendo productRoutes, quoteRoutes, adminRoutes, toolsRoutes, homeAndClientRoutes (montado último para capturar *).
Prefetching Inteligente
src/routes/RoutePrefetcher.tsx
Monitora pathname via useLocation(). Prefetch imediato para /login, /, /produtos. Delayed 2s para outras rotas, com exclusões para /orcamentos/novo, /novidades. Component returns null (zero DOM impact).
Refator do App.tsx
src/App.tsx
Remove ~279 linhas de imports lazy e helpers de routing. Delega para <AppRoutes /> e <RoutePrefetcher />. Mantém providers (BrowserRouter, AuthProvider, ThemeProvider, QueryClientProvider, TooltipProvider, etc), AppBootstrapContainer e contextos intactos.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Router
  participant RoutePrefetcher
  participant Suspense
  participant ChunkLoader
  Client->>Router: navigate(pathname)
  Router->>RoutePrefetcher: notify pathname
  RoutePrefetcher->>ChunkLoader: import() (immediate or delayed)
  Router->>Suspense: render route (fallback = getFallback(pathname))
  Suspense->>ChunkLoader: request chunk if not loaded
  ChunkLoader-->>Suspense: deliver chunk
  Suspense-->>Client: render page
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning A descrição fornece contexto completo (motivação, mudanças, estrutura nova, validações) mas não segue o template de PR obrigatório (seções como 'Tipo de mudança', 'Checklist', etc. estão ausentes). Preencha o template obrigatório: adicione seção 'Tipo de mudança' (marcar 🎨 Refatoração), 'Issue relacionada' (F1-1.x), 'Checklist' (tsc, ESLint, testes) e 'Como testar' com passos reproduzíveis.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed O título descreve com precisão a mudança principal: refatoração do App.tsx (336L→67L) quebrado em arquivos organizados por área.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/app-tsx-split

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/routes/RoutePrefetcher.tsx`:
- Around line 17-35: The dynamic import() calls in RoutePrefetcher.tsx (the
fire-and-forget prefetches inside the pathname branches and the setTimeout
block) are unhandled and can cause unhandled promise rejections; add a small
helper (e.g., safePrefetch or consumeImport) that invokes import(...).catch(()
=> {/* swallow/log */}) and replace each raw import("@/...") call in the
branches and the timeout with safePrefetch(...) so failures are absorbed
(optionally log at debug level) while keeping the best-effort prefetch behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 815109cc-b0e8-4588-8e84-66bbe00c0602

📥 Commits

Reviewing files that changed from the base of the PR and between 482b31f and af6cf5e.

📒 Files selected for processing (10)
  • src/App.tsx
  • src/routes/AppRoutes.tsx
  • src/routes/RoutePrefetcher.tsx
  • src/routes/admin-routes.tsx
  • src/routes/client-routes.tsx
  • src/routes/lazy-pages.ts
  • src/routes/product-routes.tsx
  • src/routes/public-routes.tsx
  • src/routes/quote-routes.tsx
  • src/routes/tools-routes.tsx

Comment on lines +17 to +35
import("@/pages/Index");
import("@/pages/FiltersPage");
} else if (pathname === "/") {
// On dashboard, prefetch products and quotes
import("@/pages/FiltersPage");
import("@/pages/QuotesListPage");
import("@/pages/ClientsPage");
} else if (pathname === "/produtos") {
// On products page, prefetch detailed product view and tools
import("@/pages/ProductDetail");
import("@/pages/MockupGenerator");
import("@/pages/PriceSimulatorPage");
}

// Low priority prefetch for common tools
const timeoutId = setTimeout(() => {
if (pathname !== "/orcamentos/novo") import("@/pages/QuoteBuilderPage");
if (pathname !== "/novidades") import("@/pages/NoveltiesPage");
}, 2000);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verifica imports dinâmicos sem tratamento de erro no prefetcher.
set -euo pipefail

echo "== Dynamic import sem catch =="
rg -nP --type=tsx 'import\(.+\)\s*;?$' src/routes/RoutePrefetcher.tsx

echo
echo "== Dynamic import com catch =="
rg -nP --type=tsx 'import\(.+\)\.catch\(' src/routes/RoutePrefetcher.tsx || true

echo
echo "Esperado: após o ajuste, os imports de prefetch devem passar por helper com .catch()."

Repository: adm01-debug/Promo_Gifts

Length of output: 144


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# List files in src/routes/
echo "== Files in src/routes/ =="
if [ -d "src/routes" ]; then
  ls -la src/routes/ || true
else
  echo "Directory src/routes/ does not exist"
fi

echo
echo "== Search for RoutePrefetcher in repo =="
fd -i routeprefetcher . 2>/dev/null || true

Repository: adm01-debug/Promo_Gifts

Length of output: 898


🏁 Script executed:

cat -n src/routes/RoutePrefetcher.tsx

Repository: adm01-debug/Promo_Gifts

Length of output: 1777


Trate rejeições dos import() de prefetch para evitar unhandled rejection.

Os import() nas linhas 17-18, 21-23, 26-28 e 33-34 são fire-and-forget sem .catch(). Em falha de chunk ou rede, isso gera rejeição não tratada no console. Embora prefetch seja best-effort, precisa absorver explicitamente os erros.

Solução prática: envolver com helper que consome o erro:

+const prefetch = (loader: () => Promise<unknown>) => {
+  void loader().catch(() => {
+    // prefetch é best-effort, falhas são silenciosas
+  });
+};

 import("@/pages/Index");
-import("@/pages/FiltersPage");
+prefetch(() => import("@/pages/FiltersPage"));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/routes/RoutePrefetcher.tsx` around lines 17 - 35, The dynamic import()
calls in RoutePrefetcher.tsx (the fire-and-forget prefetches inside the pathname
branches and the setTimeout block) are unhandled and can cause unhandled promise
rejections; add a small helper (e.g., safePrefetch or consumeImport) that
invokes import(...).catch(() => {/* swallow/log */}) and replace each raw
import("@/...") call in the branches and the timeout with safePrefetch(...) so
failures are absorbed (optionally log at debug level) while keeping the
best-effort prefetch behavior.

PR #119 quebrou o App.tsx em arquivos por área em src/routes/, mas o
`scripts/smoke-tests.mjs` ainda lia APENAS `src/App.tsx` procurando
strings 'path="..."'. Como os paths foram movidos pra src/routes/*.tsx,
o gate quebrou nas 7 rotas críticas:

  /login, /reset-password, /auth/callback, /produtos, /orcamentos,
  /orcamentos/novo, /admin/usuarios

Patch: `checkStaticRoutes()` agora lê App.tsx + todos os .tsx/.ts em
src/routes/, concatena, e procura os paths em todos eles.

Validado localmente:
  ✓ static-routes: 7 rotas críticas declaradas

Risk: 🟢 zero. Smoke test apenas.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refatora a árvore de rotas do app, extraindo o conteúdo antes concentrado em src/App.tsx para módulos em src/routes/ por “área”, mantendo App.tsx focado em providers/wrappers e delegando o <Routes> para um orquestrador (AppRoutes).

Changes:

  • Extrai <Routes> + RouteSuspense para src/routes/AppRoutes.tsx e reduz src/App.tsx para composição de providers e estrutura.
  • Centraliza imports lazy (via lazyWithRetry) em src/routes/lazy-pages.ts e distribui as rotas em arquivos por domínio (public/product/quote/admin/tools/client).
  • Extrai RoutePrefetcher para src/routes/RoutePrefetcher.tsx.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/App.tsx Remove definição inline de rotas/lazy imports e passa a renderizar AppRoutes + RoutePrefetcher sob os providers existentes.
src/routes/AppRoutes.tsx Orquestra a árvore de rotas (public + ProtectedRoute com subgrupos) e aplica Suspense com getFallback(pathname).
src/routes/RoutePrefetcher.tsx Implementa prefetch de chunks por pathname e prefetch de baixa prioridade via setTimeout.
src/routes/lazy-pages.ts Centraliza todos os lazyWithRetry(() => import(...)) para pages por área.
src/routes/public-routes.tsx Define rotas públicas (login/reset/callback/unauthorized).
src/routes/product-routes.tsx Define rotas de produtos (lista/detalhe/filtros/etc) e redirects legados.
src/routes/quote-routes.tsx Define rotas de orçamentos (lista/dashboard/kanban/templates/builder/view).
src/routes/admin-routes.tsx Define rotas admin sob AdminRoute, com subset dev-only sob DevRoute, e rotas deprecated.
src/routes/tools-routes.tsx Define rotas de ferramentas (simuladores, BI, mockup, kits, dropbox, etc) + redirects.
src/routes/client-routes.tsx Define home/dashboard/CRM + redirects legados e catch-all * (404).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +13 to +35
useEffect(() => {
// Only prefetch if we're not on a mobile connection or low power mode if detectable
if (pathname === "/login") {
// Prefetch index/produtos right after login screen loads
import("@/pages/Index");
import("@/pages/FiltersPage");
} else if (pathname === "/") {
// On dashboard, prefetch products and quotes
import("@/pages/FiltersPage");
import("@/pages/QuotesListPage");
import("@/pages/ClientsPage");
} else if (pathname === "/produtos") {
// On products page, prefetch detailed product view and tools
import("@/pages/ProductDetail");
import("@/pages/MockupGenerator");
import("@/pages/PriceSimulatorPage");
}

// Low priority prefetch for common tools
const timeoutId = setTimeout(() => {
if (pathname !== "/orcamentos/novo") import("@/pages/QuoteBuilderPage");
if (pathname !== "/novidades") import("@/pages/NoveltiesPage");
}, 2000);
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/smoke-tests.mjs (1)

77-82: ⚡ Quick win

Varredura de src/routes está só no nível raiz

Hoje o script ignora subpastas em src/routes. Se a organização evoluir para diretórios por domínio, esse check pode falhar com falso negativo e bloquear CI sem regressão real.

💡 Diff sugerido (coleta recursiva)
-  if (existsSync(routesDir)) {
-    for (const name of readdirSync(routesDir)) {
-      if (name.endsWith(".tsx") || name.endsWith(".ts")) {
-        candidates.push(resolve(routesDir, name));
-      }
-    }
-  }
+  const collectRouteFiles = (dir) => {
+    const files = [];
+    for (const entry of readdirSync(dir, { withFileTypes: true })) {
+      const fullPath = resolve(dir, entry.name);
+      if (entry.isDirectory()) {
+        files.push(...collectRouteFiles(fullPath));
+      } else if (entry.name.endsWith(".tsx") || entry.name.endsWith(".ts")) {
+        files.push(fullPath);
+      }
+    }
+    return files;
+  };
+
+  if (existsSync(routesDir)) {
+    candidates.push(...collectRouteFiles(routesDir));
+  }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/smoke-tests.mjs` around lines 77 - 82, The loop that reads routesDir
using readdirSync only inspects the top-level entries (the block iterating over
readdirSync(routesDir) and pushing into candidates when name.endsWith(".tsx") or
".ts") and thus ignores nested subdirectories; change this to a recursive
directory walker (e.g., a helper like collectRouteFiles or inline recursion)
that traverses subfolders under routesDir, checks Dirent/file types (readdirSync
with { withFileTypes: true } or statSync) and pushes any .ts/.tsx files into the
candidates array so that nested route files are discovered properly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/smoke-tests.mjs`:
- Line 89: The current route-checking logic uses src.includes(`path="${r}"`)
which is brittle and misses valid variants (single quotes, spaces). Replace the
naive includes check used where REQUIRED_ROUTES is filtered (the const missing =
... expression using src.includes) with a regex-based match that looks for
path\s*=\s*(['"`]){route}\1 or otherwise matches path attribute with single or
double quotes and optional spaces; implement this by constructing a RegExp from
each route (escape special chars) and testing src.match or RegExp.test so the
missing calculation correctly detects routes regardless of quoting/spacing.

---

Nitpick comments:
In `@scripts/smoke-tests.mjs`:
- Around line 77-82: The loop that reads routesDir using readdirSync only
inspects the top-level entries (the block iterating over readdirSync(routesDir)
and pushing into candidates when name.endsWith(".tsx") or ".ts") and thus
ignores nested subdirectories; change this to a recursive directory walker
(e.g., a helper like collectRouteFiles or inline recursion) that traverses
subfolders under routesDir, checks Dirent/file types (readdirSync with {
withFileTypes: true } or statSync) and pushes any .ts/.tsx files into the
candidates array so that nested route files are discovered properly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a99ec626-19bf-42bf-86ad-d9afb551b8a3

📥 Commits

Reviewing files that changed from the base of the PR and between af6cf5e and 2a05aa5.

📒 Files selected for processing (1)
  • scripts/smoke-tests.mjs

Comment thread scripts/smoke-tests.mjs
}
const src = readFileSync(appPath, "utf8");
const src = existing.map((p) => readFileSync(p, "utf8")).join("\n");
const missing = REQUIRED_ROUTES.filter((r) => !src.includes(`path="${r}"`));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Match de rota está frágil e pode gerar falso negativo

includes(\path="${r}"`)só cobre formato exato. Qualquer variação válida (aspas simples ou espaços em volta de=`) quebra o check estático.

💡 Diff sugerido (regex mais resiliente)
+  const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
-  const missing = REQUIRED_ROUTES.filter((r) => !src.includes(`path="${r}"`));
+  const missing = REQUIRED_ROUTES.filter((r) => {
+    const pattern = new RegExp(`path\\s*=\\s*["']${escapeRegExp(r)}["']`);
+    return !pattern.test(src);
+  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const missing = REQUIRED_ROUTES.filter((r) => !src.includes(`path="${r}"`));
const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const missing = REQUIRED_ROUTES.filter((r) => {
const pattern = new RegExp(`path\\s*=\\s*["']${escapeRegExp(r)}["']`);
return !pattern.test(src);
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/smoke-tests.mjs` at line 89, The current route-checking logic uses
src.includes(`path="${r}"`) which is brittle and misses valid variants (single
quotes, spaces). Replace the naive includes check used where REQUIRED_ROUTES is
filtered (the const missing = ... expression using src.includes) with a
regex-based match that looks for path\s*=\s*(['"`]){route}\1 or otherwise
matches path attribute with single or double quotes and optional spaces;
implement this by constructing a RegExp from each route (escape special chars)
and testing src.match or RegExp.test so the missing calculation correctly
detects routes regardless of quoting/spacing.

@adm01-debug adm01-debug merged commit bf305b7 into main May 9, 2026
14 of 15 checks passed
@adm01-debug adm01-debug deleted the refactor/app-tsx-split branch May 9, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants