feat(defer): add options parameter with name field for debugging#25
feat(defer): add options parameter with name field for debugging#25
Conversation
Add a DeferOptions interface as the second parameter to the defer function. The optional name field helps with debugging RSC payloads: - Development: name is included in the payload file name - Production: name is logged when the payload file is emitted
There was a problem hiding this comment.
Pull request overview
This PR adds an optional DeferOptions parameter to the defer() function, introducing a name field for debugging purposes. The name is included in development payload file names (via sanitized ID) and logged during production builds when files are emitted.
Changes:
- Added
DeferOptionsinterface with optionalnamefield for debugging - Added
sanitizeName()function to sanitize names for use in file paths - Updated
defer()function to accept options parameter and incorporate name into payload IDs - Threaded the name field through the entire processing pipeline from registration through build output
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/static/src/rsc/defer.tsx | Added DeferOptions interface, sanitizeName function, and updated defer() to accept options; modified DeferEntry and DeferRegistry to store and propagate name field |
| packages/static/src/entries/server.ts | Exported DeferOptions type for public API consumption |
| packages/static/src/build/rscProcessor.ts | Updated ProcessedComponent and RawComponent interfaces to include name field; modified processRscComponents to track and propagate names |
| packages/static/src/build/buildApp.ts | Updated writeFileNormal to accept and log optional name parameter when writing deferred component files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const sanitizedName = name ? sanitizeName(name) : undefined; | ||
| const rawId = sanitizedName | ||
| ? `${sanitizedName}-${crypto.randomUUID()}` | ||
| : crypto.randomUUID(); |
There was a problem hiding this comment.
The sanitizeName function can return an empty string when the input contains only non-alphanumeric characters (e.g., "!!!" or "###"). This would result in a rawId starting with a hyphen like "-abc-123-uuid", which may cause issues with file paths or module IDs. Consider adding a check to handle this edge case, such as falling back to undefined when the sanitized result is empty.
Add a DeferOptions interface as the second parameter to the defer function.
The optional name field helps with debugging RSC payloads: