Performance: Component naming conventions
Component naming conventions mainly affect developer experience and maintainability, indirectly influencing performance by enabling better code organization and reuse.
<!-- Use PascalCase with descriptive names like <UserCard> --> <script> import UserCard from './UserCard.svelte'; </script> <UserCard />
<!-- Using inconsistent or generic names like <component1> or <mycomponent> --> <script> import Component1 from './Component1.svelte'; </script> <Component1 />
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Generic or inconsistent names | May cause duplicate components in DOM | Potential extra reflows if duplicates render | Higher paint cost due to redundant nodes | [X] Bad |
| Consistent PascalCase descriptive names | Clear single component instance in DOM | Minimal reflows due to reuse | Lower paint cost with optimized DOM | [OK] Good |
UserProfile.svelte uses PascalCase correctly.LoginForm.svelte, which is the correct way to import and use it in another Svelte file?Filename: userprofile.svelte
Usage: <UserProfile />
userprofile.svelte is all lowercase, which is not recommended for Svelte components.<UserProfile /> uses PascalCase, which expects the filename to match in PascalCase.NavBar.svelte and navBar.svelte. What problem might this cause in a Svelte project on a case-sensitive file system?NavBar.svelte and navBar.svelte are different files but can cause confusion in imports.Pass the test and this pattern moves unknown