fix: replace @bugsnag/cuid with nanoid for edge compatibility (#3147)#3175
fix: replace @bugsnag/cuid with nanoid for edge compatibility (#3147)#3175deepshekhardas wants to merge 3 commits intotriggerdotdev:mainfrom
Conversation
Corrected the order of env file loading to follow standard precedence conventions where local and environment-specific files override the base .env file.
🦋 Changeset detectedLatest commit: bd0414a The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hi @deepshekhardas, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThis pull request modifies three files to update environment variable resolution and internal ID generation. The primary change reorders and updates the list of environment variable files considered during dot-env loading in the CLI utilities. A second change replaces the internal ID generation mechanism from cuid() to idGenerator(), removing a dependency on Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes ✨ 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 |
There was a problem hiding this comment.
🟡 Dead @bugsnag/cuid dependency left in package.json after removing its only import
The import cuid from "@bugsnag/cuid" was removed from packages/core/src/v3/isomorphic/friendlyId.ts (the only file that used it), but "@bugsnag/cuid": "^3.1.1" was not removed from packages/core/package.json:171. This means @bugsnag/cuid is a dead runtime dependency that will still be installed and bundled for all consumers of @trigger.dev/core, adding unnecessary bloat — which is ironic given the PR's stated goal of improving edge compatibility by removing cuid.
(Refers to line 171)
Was this helpful? React with 👍 or 👎 to provide feedback.
| export function generateInternalId() { | ||
| return cuid(); | ||
| return idGenerator(); | ||
| } |
There was a problem hiding this comment.
🚩 nanoid character set is compatible with existing cuid-based database IDs
The switch from cuid() to idGenerator() (nanoid with alphabet 123456789abcdefghijkmnopqrstuvwxyz, length 21) changes the format of newly generated internal IDs. CUIDs are 25 chars from [a-z0-9]; nanoid IDs will be 21 chars from a 33-char subset ([a-z0-9] minus 0 and l). The database schema uses String columns with @default(cuid()) as a Prisma fallback, but IdUtil.generate() provides the ID explicitly. Since both old and new IDs are plain strings stored in unconstrained String columns, there's no schema incompatibility. However, new IDs will not sort chronologically the way CUIDs do (CUIDs embed a timestamp). If any code path depends on lexicographic ID ordering correlating with creation time, this could be a subtle behavioral change. A search of the run-engine for sorting/ordering by raw ID didn't surface any such pattern, but this is worth being aware of.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
The
@bugsnag/cuidpackage used inpackages/coreto generate internal IDs relies on Node.js-specific APIs likeprocess.pidandos.hostname(). These APIs are not available in Edge runtimes like Supabase Edge Functions (Deno), causing the SDK to throw aTypeError: Cannot read properties of undefined (reading 'toString').This PR replaces
@bugsnag/cuidwithnanoid, which is already a project dependency and is compatible with Edge/Deno runtimes.Closes #3147
Changes
@bugsnag/cuidwithnanoidinpackages/core/src/v3/isomorphic/friendlyId.ts.@bugsnag/cuidfrompackages/core/package.json.Testing
generateInternalId()still produces unique, URL-safe alphanumeric IDs usingnanoid.