Changed skeleton component to use an integer-based key instead of a UUID#26745
Conversation
WalkthroughThe skeleton component in 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/shade/src/components/ui/skeleton.tsx (1)
32-32: Use index-based keys for this fixed-order skeleton list.
Math.random()avoids the secure-context crash fromcrypto.randomUUID(), but React explicitly warns against generating keys "on the fly" because they won't match between renders and force unnecessary remounts. For a static-order placeholder list like skeleton rows, using the index as the key is stable and acceptable.♻️ Suggested refactor
- uniqueKeys.push(`skeleton-${Math.random().toString(36).substring(2, 15)}`); + uniqueKeys.push(`skeleton-${i}`);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/shade/src/components/ui/skeleton.tsx` at line 32, Replace the unstable Math.random()-based keys with stable index-based keys for the fixed-order skeleton list: instead of pushing `skeleton-${Math.random()...}` into uniqueKeys, derive keys from the item's index (e.g., `skeleton-${index}`) or use the index directly when mapping/rendering; update the code that builds `uniqueKeys` and any rendering that uses those keys so they use the index-based key for `uniqueKeys` to avoid remounts caused by changing random keys.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/shade/src/components/ui/skeleton.tsx`:
- Line 32: Replace the unstable Math.random()-based keys with stable index-based
keys for the fixed-order skeleton list: instead of pushing
`skeleton-${Math.random()...}` into uniqueKeys, derive keys from the item's
index (e.g., `skeleton-${index}`) or use the index directly when
mapping/rendering; update the code that builds `uniqueKeys` and any rendering
that uses those keys so they use the index-based key for `uniqueKeys` to avoid
remounts caused by changing random keys.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 19fd7744-6b75-4de3-81be-c3895a5f1f14
📒 Files selected for processing (1)
apps/shade/src/components/ui/skeleton.tsx
…eton ref #26745 Avoids secure-context crash on non-HTTPS and prevents unnecessary React remounts
5e1f326 to
82f5ee2
Compare
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
|
@troyciesco no rush at all this, just a random little one I came across in my adventures |
no ref
When running Ghost in development with
yarn devin a remote VM, the analytics app crashes when loading over a plaintext http connection becausecrypto.randomUUIDis only available in a secure context (https or localhost).crypto.randomUUIDis also overkill for React keys anyways, so this changes to using integers instead, to make it easier to develop Ghost in a remote VM environment.