Files
dify/web/app/components/apps
yyh de62812134 refactor(web): centralize role-based route guards and fix anti-patterns
Problems:
- Identical useEffect + router.replace guard for dataset_operator role
  duplicated across 4 leaf components (tools/page, appDetail/layout,
  explore/index, apps/list), violating DRY and risking permission gaps
  when new routes are added
- datasets/list had a redundant role guard already covered by
  datasets/layout
- datasets/layout used useEffect for redirect, causing content flash
- useEffect-based guards render unauthorized content before redirect
- explore/index used useState + useEffect to derive hasEditPermission,
  an unnecessary render cycle (rerender-derived-state-no-effect)
- apps/list imported 6 @remixicon/react components instead of using
  Tailwind CSS icon classes, inflating JS bundle
- apps/list contained unused validTabs Set (dead code)

Solutions:
- Create RoleRouteGuard component at (commonLayout)/layout.tsx level
  that synchronously checks role during render and returns null before
  children mount, preventing content flash
- Remove all 5 duplicated useEffect guards from leaf components
- Replace datasets/layout useEffect guard with synchronous render check
- Derive hasEditPermission directly during render in explore/index
- Replace @remixicon/react imports with i-ri-* CSS icon classes
- Remove dead code (validTabs)
2026-02-13 14:58:21 +08:00
..