Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…ation Co-authored-by: Starefossen <968267+Starefossen@users.noreply.github.com>
Co-authored-by: Starefossen <968267+Starefossen@users.noreply.github.com>
|
@copilot rebase on main |
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||
|
@copilot rebase on main, review the code review comments and run all the checks and tests. |
|
This is a good change! Is there a reason why we mock nanoid here? If there is, since the reason is not immediately apparent to me, and the ai has commented on it too, maybe we can leave a comment in the code about it? |
|
The mock is probably leftover from jest's missing esm support - partly why we migrated to vi 😅 |
|
@copilot yo, no more mocking around with nanoid in the tests, ok? Just use the real deal 😎 |
Done! Removed the nanoid mock and rebased on main. The tests now use the real nanoid implementation, which works perfectly with Vitest's ESM support. Commit dd242b5 contains only the test file without any mock. |
|
@copilot remove jest |
Co-authored-by: Starefossen <968267+Starefossen@users.noreply.github.com>
Standardize unique key generation using nanoid
Client-side key generation using
Date.now()andMath.random()can produce collisions during rapid operations. This PR standardizes onnanoidfor all_keyfields in Sanity arrays.Changes Made
Core library update
lib/sanity/helpers.ts: Replaced${prefix}-${Date.now()}-${Math.random()...}with${prefix}-${nanoid()}ingenerateKey()Component updates
SponsorPortal.tsx: Contact keys now usenanoid()directlycontract-templates.ts: Section keys usenanoid()instead of sequential counter or timestampTicketPageContentEditor.tsx: ReplacedMath.random().toString(36)withnanoid()__mocks__/sponsor-data.ts,SponsorContactEditor.stories.tsx: Updated to match patternTest infrastructure
__tests__/lib/sanity/helpers.test.tswith collision resistance validation using real nanoid implementationTest framework migration
jest.config.ts,jest.setup.ts)vitest.config.ts,vitest.setup.ts)Example
Before:
After:
The
generateKey()helper now propagates nanoid throughout the codebase, ensuring consistent collision-resistant key generation. All tests validate actual nanoid behavior without mocking.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
PR Type
Enhancement
Description
Standardized unique key generation using
nanoidacross codebaseReplaced
Date.now()andMath.random()with collision-resistantnanoid()Added comprehensive test suite for key generation helpers
Updated Jest configuration with nanoid mock module mapping
Diagram Walkthrough
File Walkthrough
6 files
Replace Date.now() with nanoid in generateKeyUse nanoid for contact key generationReplace sequential counter with nanoid for sectionsReplace Math.random with nanoid for key generationUpdate mock data to use nanoidReplace Date.now with nanoid in story demo2 files
Add comprehensive tests for key generation helpersCreate deterministic nanoid mock for testing1 files
Add nanoid module mapping to Jest configurationGreptile Summary
Standardized unique key generation across the codebase by migrating from
Date.now()andMath.random()to the collision-resistantnanoidlibrary for all Sanity_keyfields.Key Changes:
generateKey()helper insrc/lib/sanity/helpers.tsnow usesnanoid()instead of timestamp + random stringImpact:
_keygenerationDate.now()andMath.random()for key generation have been migratedConfidence Score: 5/5
Important Files Changed
Date.now()andMath.random()with collision-resistantnanoid()ingenerateKey()functionnanoid()for collision-resistant unique keysnanoid()for uniquenessMath.random().toString(36)withnanoid()for ticket content keysnanoid()for generating test contact keysnanoid()for dynamic contact key generationFlowchart
flowchart TD A[Old: Date.now + Math.random] -->|Replace| B[nanoid Library] B --> C[generateKey Helper] C --> D[Sanity Helpers] C --> E[Component Keys] D --> D1[ensureArrayKeys] D --> D2[createReferenceWithKey] E --> E1[SponsorPortal Contacts] E --> E2[Contract Sections] E --> E3[Ticket Content] E --> E4[Mock Data] B -.Mock.-> F[Jest Test Mock] F --> G[Deterministic Counter] C --> H[Test Suite] H --> H1[Uniqueness Tests] H --> H2[Collision Tests]Last reviewed commit: a4870f1