Add ember-best-practices skill

This commit is contained in:
2026-04-01 12:59:41 +04:00
parent 913d5c915c
commit ecbac12440
65 changed files with 19863 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
---
title: Use Loading Substates for Better UX
impact: CRITICAL
impactDescription: Perceived performance improvement
tags: routes, loading, ux, performance
---
## Use Loading Substates for Better UX
Implement loading substates to show immediate feedback while data loads, preventing blank screens and improving perceived performance.
**Incorrect (no loading state):**
```javascript
// app/routes/posts.js
export default class PostsRoute extends Route {
async model() {
return this.store.request({ url: '/posts' });
}
}
```
**Correct (with loading substate):**
```glimmer-js
// app/routes/posts-loading.gjs
import { LoadingSpinner } from './loading-spinner';
<template>
<div class="loading-spinner" role="status" aria-live="polite">
<span class="sr-only">Loading posts...</span>
<LoadingSpinner />
</div>
</template>
```
```javascript
// app/routes/posts.js
export default class PostsRoute extends Route {
model() {
// Return promise directly - Ember will show posts-loading template
return this.store.request({ url: '/posts' });
}
}
```
Ember automatically renders `{route-name}-loading` route templates while the model promise resolves, providing better UX without extra code.