Cyclic dependencies are likely the root cause of our development server crashes and are also contributing to memory leaks during runtime. These issues primarily occur because types, constants, and enums are not being imported from a common file, leading to circular references between modules.
<aside>
💡 Run npx dpdm —help
to make sure dpdm
is installed. If it isn’t installed, running npx dpdm
should prompt for installing the package.
</aside>
To check the cyclic dependencies introduced in a PR follow the steps below.
cd app/client
npx dpdm "./src/**/*.{js,jsx,ts,tsx}" --circular --warning=false --tree=false | sed 's/^[[:space:]]*[0-9]\\{4\\})[[:space:]]*/ # /' > release_circular_deps.txt
cd app/client
npx dpdm "./src/**/*.{js,jsx,ts,tsx}" --circular --warning=false --tree=false | sed 's/^[[:space:]]*[0-9]\\{4\\})[[:space:]]*/ # /' > pr_circular_deps.txt
diff -u release_circular_deps.txt pr_circular_deps.txt | grep -E '^[+-]' > diff.txt
Any line prefixed with a +
indicates that your PR added that cyclic dependency, while a line prefixed with a -
indicates that your PR removed that cyclic dependency.
❌ Don't define types in component or business logic files
// UserProfile.tsx
export interface UserData { ... }
export const UserProfile = () => { ... }
âś… Do create dedicated type files
// types/user.ts
export interface UserData { ... }
// UserProfile.tsx
import { UserData } from '../types/user';