Repository navigation
feat: support IDE feature Go to defintion - #1008
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
🦋 Changeset detectedLatest commit: b132bf9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
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 |
WalkthroughThe changes in this pull request introduce new type definitions and enhance existing ones across various files, primarily focusing on the Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
📦 Bundle size comparison
|
More templates
@uploadthing/nuxt
@uploadthing/react
@uploadthing/shared
@uploadthing/solid
@uploadthing/svelte
@uploadthing/vue
uploadthing
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (5)
examples/minimal-appdir/src/utils/uploadthing.ts (2)
12-13: LGTM! Enhanced export supports IDE features.The addition of
routeRegistryto the exported members fromgenerateReactHelpersis a positive change. This enhancement aligns with the PR objective of supporting the "Go to definition" IDE feature, which can significantly improve developer experience.Consider documenting the usage and benefits of
routeRegistryin your project's documentation or README. This will help other developers understand its purpose and how to leverage it effectively.
Line range hint
1-13: Overall, the changes enhance functionality while maintaining code quality.The modifications to this file are well-structured and align with the PR's objective. The addition of
routeRegistryto the exports enhances the file's utility without compromising its clarity or focus. The consistent use of theOurFileRoutertype across exports maintains type safety.As the project evolves, consider:
- Documenting the purpose and usage of
routeRegistryfor other developers.- Ensuring that the
OurFileRoutertype definition (imported from "~/server/uploadthing") remains up-to-date with any changes to the upload functionality.- Monitoring the usage of these exports in the broader project to identify any potential optimizations or refactoring opportunities.
examples/minimal-appdir/src/app/page.tsx (1)
Line range hint
1-75: Overall, good changes with a minor inconsistency.The modifications in this file successfully implement the use of
routeRegistry, improving type safety and enabling IDE features like "Go to definition". This aligns well with the PR objectives. The changes are consistent across most of the file, with the exception of theUploadDropzonecomponent.To fully achieve the PR's goals:
- Update the
UploadDropzonecomponent to userouteRegistry.videoAndImage.- Double-check if there are any other components or hooks in the codebase that might benefit from similar updates.
Great work on enhancing the developer experience with these changes!
packages/react/src/useUploadThing.ts (2)
187-192: LGTM:routeRegistryexport and documentation.The addition of
routeRegistryto the return object and its accompanying JSDoc comment are well-implemented. This change makes the new feature available to consumers and provides clear documentation.Consider adding an
@examplesection to the JSDoc comment to illustrate how developers can use this feature in their IDE. This could further enhance the documentation and ease of use.
Line range hint
1-193: Overall implementation looks great!The changes to implement the
routeRegistryfeature are well-executed and focused. They achieve the PR objective of supporting the "Go to definition" IDE feature without introducing unnecessary modifications to the existing code. The implementation is consistent with the file's structure and coding style.To further improve the modularity of the codebase, consider extracting the
routeRegistrycreation and related logic into a separate utility function or module. This could make it easier to reuse or extend this functionality in the future if needed.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
- examples/minimal-appdir/src/app/page.tsx (2 hunks)
- examples/minimal-appdir/src/utils/uploadthing.ts (1 hunks)
- packages/react/src/useUploadThing.ts (4 hunks)
- packages/shared/src/dropzone-utils.ts (0 hunks)
- packages/shared/src/utils.ts (1 hunks)
- packages/uploadthing/src/types.ts (1 hunks)
💤 Files with no reviewable changes (1)
- packages/shared/src/dropzone-utils.ts
🧰 Additional context used
🔇 Additional comments (9)
examples/minimal-appdir/src/utils/uploadthing.ts (1)
12-13: Verify usage ofrouteRegistryin the project.The addition of
routeRegistryto the exported members is a good enhancement. To ensure it's being utilized effectively:
- Check if
routeRegistryis imported and used in other parts of the project.- Verify that any existing usage of
useUploadThingremains unaffected.Run the following script to check the usage of
routeRegistryanduseUploadThing:This script will help identify any potential issues or areas that might need updates following this change.
✅ Verification successful
Usage of
routeRegistryanduseUploadThingVerified Successfully.The addition of
routeRegistryhas been correctly integrated and is utilized in the project without affecting existing functionality.
- Verified usage in
examples/minimal-appdir/src/app/page.tsx.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check usage of routeRegistry and useUploadThing in the project # Search for imports of routeRegistry echo "Searching for imports of routeRegistry:" rg --type typescript --type javascript 'import.*routeRegistry.*from.*uploadthing' # Search for usage of routeRegistry echo "\nSearching for usage of routeRegistry:" rg --type typescript --type javascript 'routeRegistry\.' # Verify existing usage of useUploadThing echo "\nVerifying existing usage of useUploadThing:" rg --type typescript --type javascript 'useUploadThing'Length of output: 582
Script:
#!/bin/bash # Description: Check usage of routeRegistry and useUploadThing in the project # Search for imports of routeRegistry echo "Searching for imports of routeRegistry:" rg 'import.*routeRegistry.*from.*uploadthing' -g '*.ts' -g '*.tsx' -g '*.js' -g '*.jsx' # Search for usage of routeRegistry echo "\nSearching for usage of routeRegistry:" rg 'routeRegistry\.' -g '*.ts' -g '*.tsx' -g '*.js' -g '*.jsx' # Verify existing usage of useUploadThing echo "\nVerifying existing usage of useUploadThing:" rg 'useUploadThing' -g '*.ts' -g '*.tsx' -g '*.js' -g '*.jsx'Length of output: 8258
examples/minimal-appdir/src/app/page.tsx (2)
4-7: LGTM: Import statement updated correctly.The addition of
routeRegistryto the import statement is in line with the PR objective. This change supports the "Go to definition" IDE feature by making the route registry accessible in this component.
11-11: Excellent: Improved type safety inuseUploadThinghook.The change from a string literal to
routeRegistry.videoAndImageenhances type safety and supports the "Go to definition" IDE feature. This modification aligns well with the PR objectives while maintaining the existing hook configuration.packages/uploadthing/src/types.ts (1)
163-165: LGTM! Consider providing usage examples.The new
RouteRegistrytype is a well-implemented mapped type that should enhance type safety when working with routes defined in theFileRouter. This addition aligns well with the PR objective of supporting the "Go to definition" IDE feature.To better understand the intended usage and impact of this new type, could you provide some examples of how
RouteRegistrywill be used in the codebase? This would help ensure that the implementation fully meets the requirements for the "Go to definition" feature.To verify the potential usage of this new type, let's run the following script:
This script will help us understand if there are any immediate uses of the new
RouteRegistrytype or if there are preparations being made for its use in other parts of the codebase.✅ Verification successful
To address the issue with the previous shell scripts, let's update them to use the correct file type for TypeScript. Please run the following scripts to gather the necessary information:
Verified!
RouteRegistryis utilized inuseUploadThing.tsto enhance type safety.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for potential usages or preparations for the RouteRegistry type # Test 1: Search for any imports or uses of RouteRegistry echo "Searching for RouteRegistry usage:" rg --type typescript "RouteRegistry" -g '!packages/uploadthing/src/types.ts' # Test 2: Search for any new types or functions that might be using this type echo "Searching for potential related new types or functions:" rg --type typescript "type.*=.*FileRouter" -g '!packages/uploadthing/src/types.ts' # Test 3: Search for any modifications to existing types or functions that might be preparing for this type echo "Searching for modifications to existing types or functions:" rg --type typescript "(type|interface|function).*FileRouter" -g '!packages/uploadthing/src/types.ts'Length of output: 698
Script:
# #!/bin/bash # Description: Search for potential usages or preparations for the RouteRegistry type with corrected file type # Test 1: Search for any imports or uses of RouteRegistry echo "Searching for RouteRegistry usage:" rg --type ts "RouteRegistry" -g '!packages/uploadthing/src/types.ts' # Test 2: Search for any new types or functions that might be using this type echo "Searching for potential related new types or functions:" rg --type ts "type\s+.*\s+=\s+FileRouter" -g '!packages/uploadthing/src/types.ts' # Test 3: Search for any modifications to existing types or functions that might be preparing for this type echo "Searching for modifications to existing types or functions:" rg --type ts "(type|interface|function)\s+.*\s+FileRouter" -g '!packages/uploadthing/src/types.ts'Length of output: 6021
packages/react/src/useUploadThing.ts (2)
8-8: LGTM: New imports support therouteRegistryfeature.The addition of
createIdentityProxyandRouteRegistryimports are necessary for implementing the newrouteRegistryfeature. This change enhances type safety and IDE integration for backend route definitions.Also applies to: 23-23
174-175: LGTM:routeRegistryimplementation supports IDE "Go to definition" feature.The addition of
routeRegistryusingcreateIdentityProxyis a clever way to enable IDE "Go to definition" functionality for backend route definitions. This enhances developer experience and aligns perfectly with the PR objective.packages/shared/src/utils.ts (3)
355-357: LGTM:noopfunction implementationThe
noop(no-operation) function is correctly implemented. This is a common and useful utility in JavaScript/TypeScript projects, often used for default callbacks or as placeholders. Its addition aligns well with the PR's objective of supporting IDE features like "Go to definition".
354-362: Summary: New utility functions align with PR objectivesThe addition of
noopandcreateIdentityProxyfunctions appears to support the PR's objective of implementing the "Go to definition" IDE feature. Both functions are correctly implemented and provide useful utilities for the project.The
noopfunction is a standard no-operation utility that can be used in various contexts. ThecreateIdentityProxyfunction, while well-implemented, would benefit from additional context or documentation to clarify its specific use case within the project.Overall, these additions enhance the utility functions available in the codebase and seem to contribute positively to the project's development tooling.
359-362: Approve implementation, but clarify usage:createIdentityProxyfunctionThe
createIdentityProxyfunction is well-implemented using a Proxy object to return the property name when any property is accessed. The use of generics allows for flexible typing. This implementation aligns with the PR's objective of supporting IDE features like "Go to definition".However, could you please clarify the intended use case for this function within the project? Understanding its purpose would help ensure it fits well with the overall architecture and doesn't introduce any potential issues.
To better understand the usage of
createIdentityProxy, let's search for its occurrences in the codebase:✅ Verification successful
[/run_scripts]
Approve implementation:
createIdentityProxyfunction usage clarifiedThe
createIdentityProxyfunction is utilized to create therouteRegistryobject, which enhances IDE features like "Go to definition" for backend route definitions. This usage aligns with the intended purpose of improving developer tooling within the project.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for usages of createIdentityProxy rg "createIdentityProxy" --type tsLength of output: 310
Script:
#!/bin/bash # Extract lines where routeRegistry is used in useUploadThing.ts rg "routeRegistry" packages/react/src/useUploadThing.ts -A 5 -B 5Length of output: 474
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
packages/react/src/types.ts (1)
30-33: LGTM: New Endpoint type enhances flexibilityThe new
Endpointtype and its usage inUploadthingComponentPropsimprove the flexibility of endpoint specification while maintaining type safety. This change aligns well with the PR objective.Consider adding a brief comment explaining the purpose and usage of the
Endpointtype for better documentation.You could add a comment like this above the
Endpointtype definition:/** * Represents an endpoint in the FileRouter. * Can be either a direct endpoint key or a function that selects an endpoint based on the RouteRegistry. */ export type Endpoint< TRouter extends FileRouter, TEndpoint extends keyof TRouter, > = TEndpoint | ((_: RouteRegistry<TRouter>) => TEndpoint);Also applies to: 119-119
packages/uploadthing/src/client.ts (1)
272-281: LGTM: Updated return statement withrouteRegistry.The
routeRegistryis correctly added to the return object ofgenUploader. The JSDoc comment provides a clear explanation of its purpose.Consider enhancing the JSDoc comment to include an example of how to use the
routeRegistry:/** * Identity object that can be used instead of raw strings * that allows "Go to definition" in your IDE to bring you * to the backend definition of a route. * * @example * const { routeRegistry } = genUploader<MyFileRouter>({ ... }); * const endpoint = routeRegistry.myEndpoint; // IDE can now provide "Go to definition" for 'myEndpoint' */ routeRegistry,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- examples/minimal-appdir/src/app/page.tsx (3 hunks)
- packages/react/src/types.ts (3 hunks)
- packages/react/src/useUploadThing.ts (4 hunks)
- packages/uploadthing/src/client.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- examples/minimal-appdir/src/app/page.tsx
- packages/react/src/useUploadThing.ts
🧰 Additional context used
🔇 Additional comments (5)
packages/react/src/types.ts (2)
14-14: LGTM: New import added for RouteRegistryThe addition of
RouteRegistryimport is consistent with the PR objective and necessary for the newEndpointtype definition.
Line range hint
1-155: Summary: Changes enhance type safety and flexibilityThe modifications to this file, including the new
Endpointtype and its usage, successfully improve type safety and flexibility in endpoint specification. These changes align well with the PR objective of supporting the "Go to definition" IDE feature. The code is well-structured and maintains consistency with the existing codebase.packages/uploadthing/src/client.ts (3)
6-6: LGTM: New import added correctly.The
createIdentityProxyimport from "@uploadthing/shared" is correctly placed with other imports from the same package. This import is necessary for the newrouteRegistryfunctionality.
28-28: LGTM: New type import added correctly.The
RouteRegistrytype import from "./types" is correctly placed with other type imports from the same file. This type is necessary for the newrouteRegistryfunctionality.
270-270: LGTM:routeRegistrycreated correctly.The
routeRegistryobject is correctly created usingcreateIdentityProxy<RouteRegistry<TRouter>>(). This implementation supports the new IDE "Go to definition" feature for backend route definitions.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (5)
examples/backend-adapters/client-vanilla/src/normal-upload.ts (1)
39-39: Consider replacing the arrow comment with a more descriptive code commentThe current comment "👇👇👇 THIS IS THE ACTUAL UPLOAD 👇👇👇" draws attention but could be more informative. Consider replacing it with a more descriptive comment that explains the purpose and importance of the following code block.
For example:
// Start the file upload process // This section handles the core upload functionality, including progress tracking and error handlingThis change would improve code readability and maintainability.
examples/backend-adapters/client-vanilla/src/resumable-upload.ts (1)
39-39: LGTM! Consider adding type annotation for improved type safety.The change from a string literal to a function aligns well with the PR objective of supporting the "Go to definition" IDE feature. This modification allows for more flexible runtime determination of the upload type while enabling better IDE support.
To further improve the code:
Consider adding a type annotation for the
rrparameter to ensure type safety:(rr: { videoAndImage: unknown }) => rr.videoAndImageVerify that the
rrobject always has the expected structure throughout the codebase to prevent potential runtime errors.packages/react/src/types.ts (1)
Line range hint
114-138: LGTM: Enhanced type safety and configurabilityThe changes to the
UploadthingComponentPropstype are well-implemented:
- The
endpointproperty now usesEndpointArg<TRouter, TEndpoint>, which enhances type safety and flexibility.- The new
configproperty allows for more customization of the upload behavior, including:
mode: Enables manual or automatic upload triggering.appendOnPaste: Likely controls file appending on paste events.cn: Allows for custom class name merging, useful for styling customization.These changes improve the overall flexibility and usability of the component.
Consider adding JSDoc comments for the
modeandappendOnPasteoptions in theconfigproperty to provide more clarity on their usage and effects.packages/uploadthing/src/types.ts (1)
168-170: LGTM:RouteRegistrytype enhances type safety.The
RouteRegistrytype effectively creates a type-safe registry of routes, which is crucial for the "Go to definition" IDE feature mentioned in the PR objectives. It's well-implemented and concise.Consider adding a brief JSDoc comment to explain the purpose of this type, which could help other developers understand its role in enabling IDE features:
/** * Creates a type-safe registry of routes, enabling IDE features like "Go to definition". */ export type RouteRegistry<TRouter extends FileRouter> = { [k in keyof TRouter]: k; };packages/react/test/client-generator.test.ts (1)
153-165: Approve new test case with a minor suggestion.The new test case "gets go-to-definition proxy as endpoint arg" is a valuable addition. It effectively verifies the type inference for both input and output when using the go-to-definition proxy with
useUploadThing. The test structure is consistent with other tests in the file.A minor suggestion for improvement:
Consider adding a comment explaining the purpose of using
(rr) => rr.withFooInputand(rr) => rr.exampleRouteas arguments touseUploadThing. This would help clarify the "go-to-definition proxy" concept for future readers. For example:it("gets go-to-definition proxy as endpoint arg", () => { doNotExecute(async () => { + // Using a callback to select the route enables IDE "go to definition" feature const { startUpload } = useUploadThing((rr) => rr.withFooInput); type _Input = Parameters<typeof startUpload>[1]; expectTypeOf<_Input>().toEqualTypeOf<{ foo: string }>(); }); doNotExecute(async () => { + // Using a callback to select the route enables IDE "go to definition" feature const { startUpload } = useUploadThing((rr) => rr.exampleRoute); const res = await startUpload(files); expectTypeOf<ClientUploadedFileData<{ foo: "bar" }>[] | undefined>(res); }); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (8)
- examples/backend-adapters/client-vanilla/src/normal-upload.ts (1 hunks)
- examples/backend-adapters/client-vanilla/src/resumable-upload.ts (1 hunks)
- packages/react/src/types.ts (2 hunks)
- packages/react/src/useUploadThing.ts (4 hunks)
- packages/react/test/client-generator.test.ts (2 hunks)
- packages/uploadthing/src/client.ts (6 hunks)
- packages/uploadthing/src/types.ts (1 hunks)
- packages/uploadthing/test/client.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/react/src/useUploadThing.ts
- packages/uploadthing/src/client.ts
🧰 Additional context used
🔇 Additional comments (9)
examples/backend-adapters/client-vanilla/src/normal-upload.ts (1)
40-49: Excellent improvement for IDE support and type safety!The modification to use
(routeRegistry) => routeRegistry.videoAndImageinstead of the string literal"videoAndImage"is a great enhancement. This change:
- Enables the "Go to definition" IDE feature, improving code navigation.
- Provides better type safety by using the
routeRegistryobject.- Maintains the existing functionality while improving the developer experience.
The rest of the
uploadFilescall remains unchanged, ensuring that the current behavior is preserved.packages/react/src/types.ts (2)
10-10: LGTM: New import enhances type safetyThe addition of the
EndpointArgimport fromuploadthing/typesis a good improvement. It likely provides more flexibility and type safety for endpoint definitions in theUploadthingComponentPropstype.
Line range hint
1-138: Summary: Improved type safety and configurabilityThe changes in this file significantly enhance the type definitions for the UploadThing library:
- The introduction of the
EndpointArgtype improves type safety for endpoint definitions.- The updates to
UploadthingComponentPropsprovide more flexibility and configurability for the upload component.These modifications align well with the PR objectives and contribute to a more robust and developer-friendly API. The added configuration options allow for fine-tuned control over the upload behavior, which should improve the overall user experience.
packages/uploadthing/src/types.ts (2)
163-166: LGTM: NewEndpointArgtype aligns with PR objectives.The new
EndpointArgtype effectively supports multiple usage methods for theuseUploadThingfunction, as outlined in the PR objectives. It allows for both direct endpoint specification and dynamic endpoint selection, enhancing flexibility for users.
162-170: Summary: New types enhance IDE support and usage flexibility.The addition of
EndpointArgandRouteRegistrytypes successfully implements the "Go to definition" IDE feature support as outlined in the PR objectives. These changes provide a type-safe and flexible way to work with uploadthing routes, enhancing the developer experience.The implementation allows for multiple usage methods of the
useUploadThingfunction, including type-safe string literals and dynamic access to symbols, as described in the PR summary.These changes are well-implemented and ready for merging.
packages/react/test/client-generator.test.ts (1)
1-1: Verify the necessity of importingdescribe.The import statement has been updated to include
describefrom "vitest". However,describeis not used in the visible changes of this file. Please ensure thatdescribeis actually used in the test suite, or remove it from the import statement if it's not needed.packages/uploadthing/test/client.test.ts (3)
124-126: Improved type safety and IDE supportThe change from using a string literal to a callback function
(rr) => rr.foois a good improvement. This new syntax allows for better type inference and enables IDE features like "Go to definition", which aligns well with the PR objectives. It maintains the same functionality while enhancing the developer experience.
Line range hint
166-171: Consistent update to test caseThis change maintains consistency with the previous update, using the callback syntax
(rr) => rr.foofor the route specification. It's good to see that the custom headers functionality remains intact, demonstrating that the new syntax doesn't interfere with existing features. This consistency across test cases helps maintain code clarity and reinforces the new usage pattern.
Line range hint
1-359: Summary of changesThe updates to this test file consistently implement the new callback syntax for specifying routes in
uploadFilesfunction calls. These changes enhance type safety and IDE support, particularly enabling the "Go to definition" feature, which aligns perfectly with the PR objectives. The modifications are focused and do not alter the underlying test logic or coverage. This update improves the developer experience while maintaining the integrity of the existing tests.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (7)
docs/src/app/(docs)/api-reference/client/page.mdx (3)
43-54: Excellent addition for improved developer experience!This note effectively explains the new feature allowing developers to use a callback function for the endpoint argument, enabling the "Go to Definition" functionality. This enhancement significantly improves code navigation and maintainability.
Consider adding a brief explanation of why this feature is beneficial, e.g., "This improves code navigation and helps maintain consistency between client and server implementations."
Line range hint
106-166: Well-documented newcreateUploadfunction!The documentation for the
createUploadfunction is comprehensive and clearly explains its purpose, parameters, and return values. The included example effectively demonstrates how to use the function for resumable uploads.Consider adding a note about any limitations or considerations when using resumable uploads, such as how long the presigned URLs remain valid or any potential impact on performance.
Line range hint
222-258: Helpful validation utility functions well-documented.The documentation for
isValidSizeandisValidTypefunctions is clear and consistent with the overall documentation style. These validation utilities will be valuable for developers implementing file upload functionality with size and type restrictions.Consider adding a brief example of how these functions might be used in conjunction with the
uploadFilesorcreateUploadfunctions to provide a complete picture of the validation process.docs/src/app/(docs)/api-reference/react/page.mdx (4)
Line range hint
269-271: Great additions to theUploadButtonproperties!The new properties
onUploadAborted,disabled, andconfig.cnsignificantly enhance the component's functionality and customizability. These additions provide developers with more control over the upload process, button state, and styling integration.Consider adding a brief example of how to use the
onUploadAbortedcallback in the documentation to help developers understand its practical application.Also applies to: 275-277, 287-290
Line range hint
387-389: Inconsistency inendpointproperty type forUploadDropzoneWhile the additions of
onUploadAborted,disabled, andconfig.cnproperties are great and maintain consistency with theUploadButtoncomponent, there's an inconsistency in theendpointproperty type. TheUploadDropzonestill useskeyof FileRouterinstead ofEndpointArg<FileRouter>as updated in theUploadButtoncomponent.Update the
endpointproperty type forUploadDropzoneto match theUploadButton:- <Property name="endpoint" type="keyof FileRouter" required> + <Property name="endpoint" type="EndpointArg<FileRouter>" required>Also, consider adding the same note about using callback functions for the
endpointargument as provided in theUploadButtondocumentation.Also applies to: 451-453, 463-466
Line range hint
495-497: Excellent updates to theuseUploadThinghook!The addition of the
signalparameter andonUploadAbortedcallback greatly improves the hook's flexibility in handling upload cancellations. The deprecation ofpermittedFileTypesin favor of the more comprehensiverouteConfigis a good move towards providing more detailed configuration information.Consider adding a brief example of how to use the new
signalparameter andonUploadAbortedcallback in the documentation. This would help developers understand how to implement upload cancellation in their applications.Also applies to: 506-508, 524-529, 534-537
Line range hint
541-586: Good example, but could be enhanced to showcase new featuresThe provided example effectively demonstrates the integration of
useDropzoneanduseUploadThinghooks, including the usage of the newrouteConfigproperty. However, it doesn't showcase the newly added upload cancellation feature.Consider enhancing the example to demonstrate how to use the
signalparameter for upload cancellation. This could include:
- Creating an
AbortController- Passing its
signalto theuseUploadThinghook- Adding a cancel button that calls
abortController.abort()Here's a snippet that could be added to the example:
const abortController = new AbortController(); const { startUpload, routeConfig } = useUploadThing("myUploadEndpoint", { signal: abortController.signal, onUploadAborted: () => { console.log("Upload aborted"); }, // ... other options }); // ... existing code <button onClick={() => abortController.abort()}>Cancel Upload</button>This addition would provide a more comprehensive example of the hook's capabilities, including the new cancellation feature.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- docs/src/app/(docs)/api-reference/client/page.mdx (1 hunks)
- docs/src/app/(docs)/api-reference/react/page.mdx (1 hunks)
- examples/minimal-appdir/src/app/page.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- examples/minimal-appdir/src/app/page.tsx
🧰 Additional context used
🔇 Additional comments (3)
docs/src/app/(docs)/api-reference/client/page.mdx (2)
Line range hint
168-183: Clear documentation forgenerateClientDropzoneAcceptfunction.The documentation for the
generateClientDropzoneAcceptfunction is concise and provides the necessary information about its purpose, parameters, and return type. This will be helpful for developers integrating file upload functionality with dropzone components.
Line range hint
185-220: Well-documented utility functions for file type handling.The documentation for
generateMimeTypesandgeneratePermittedFileTypesfunctions is clear and consistent with the overall documentation style. These utility functions will be valuable for developers working with file uploads and type validation.docs/src/app/(docs)/api-reference/react/page.mdx (1)
215-231: Excellent update to theendpointproperty documentation!The change from
keyof FileRoutertoEndpointArg<FileRouter>for theendpointproperty type, along with the added note about using callback functions, significantly improves the developer experience. This update aligns perfectly with the PR objective of supporting the "Go to definition" IDE feature, allowing developers to navigate directly to their backend file route definition.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (26)
examples/minimal-pagedir/src/pages/index.tsx (3)
Line range hint
7-13: Consider updating to use the new function-based endpoint pattern.The
useUploadThinghook is using a string literal "videoAndImage" which doesn't support the new "Go to definition" IDE feature. Consider updating to use therouteRegistrypattern for consistency with theUploadDropzonecomponent.- const { startUpload } = useUploadThing("videoAndImage", { + const { startUpload } = useUploadThing((routeRegistry) => routeRegistry.videoAndImage, {
Line range hint
15-26: Update UploadButton to demonstrate the routeRegistry pattern.Similar to the above, the
UploadButtoncomponent is using a string literal endpoint which doesn't support "Go to definition". Consider updating this to use therouteRegistrypattern for consistency.- endpoint="videoAndImage" + endpoint={(routeRegistry) => routeRegistry.videoAndImage}
Line range hint
1-58: Consider documenting the different endpoint specification patterns.Since this is an example file, it would be valuable to demonstrate and document all three usage patterns mentioned in the PR objectives:
- Type-safe string literal
- Importing
routeRegistry- Callback argument (currently shown)
This would make the example more educational and comprehensive.
Consider adding comments above each usage pattern explaining the trade-offs and benefits, for example:
// Method 1: Using type-safe string literal // - Simple but doesn't support "Go to definition" const { startUpload } = useUploadThing("videoAndImage", {}); // Method 2: Using imported routeRegistry // - Supports "Go to definition" // - Requires importing routeRegistry import { routeRegistry } from "./uploadthing"; const { startUpload2 } = useUploadThing(routeRegistry.videoAndImage, {}); // Method 3: Using callback argument (current approach) // - Supports "Go to definition" // - More verbose but doesn't require separate import const { startUpload3 } = useUploadThing((routeRegistry) => routeRegistry.videoAndImage, {});examples/with-clerk-appdir/src/app/page.tsx (1)
Line range hint
11-38: Consider documenting the different endpoint specification approaches.This file demonstrates two valid approaches for specifying endpoints:
- String literal (UploadButton):
endpoint="videoAndImage"- Callback (UploadDropzone):
endpoint={(routeRegistry) => routeRegistry.videoAndImage}Consider adding a comment explaining why different approaches are used and their respective benefits (e.g., IDE support vs. simplicity).
<UploadButton /** * @see https://docs.uploadthing.com/api-reference/react#uploadbutton + * Using string literal approach for simplicity */ endpoint="videoAndImage" // ... /> <UploadDropzone /** * @see https://docs.uploadthing.com/api-reference/react#uploaddropzone + * Using callback approach to enable IDE "Go to definition" feature */ endpoint={(routeRegistry) => routeRegistry.videoAndImage} // ... />examples/backend-adapters/client-react/src/main.tsx (1)
Line range hint
11-23: Consider updating UploadButton to use the new endpoint patternThe
UploadButtonis still using a string literal for the endpoint whileUploadDropzoneuses the new function-based approach. For consistency and to enable IDE "Go to definition" support, consider updating it to match.<UploadButton - endpoint="videoAndImage" + endpoint={(routeRegistry) => routeRegistry.videoAndImage} onClientUploadComplete={(file) => {packages/shared/test/unwrap.test.ts (3)
12-17: Consider adding negative test cases.While the current test effectively covers the happy path, consider adding negative test cases to verify behavior with invalid inputs (e.g., calling with arguments when none are expected).
Would you like me to provide examples of additional test cases?
35-40: Consider adding type-error cases for consistency.For consistency with the single argument test, consider adding type-error cases to verify behavior with missing or invalid arguments.
it("function w/ 2 args", () => { const getter = (x: number, y: number) => x + y; const value = unwrap(getter, 1, 2); expectTypeOf<number>(value); expect(value).toBe(3); + + { + // @ts-expect-error - missing args + unwrap(getter, 1); + // @ts-expect-error - invalid args + unwrap(getter, "1", "2"); + } });
42-57: LGTM! Consider adding invalid type combinations.The test thoroughly covers valid use cases with different argument combinations. Consider adding type-error cases for invalid combinations of the optional parameter.
{ const value = unwrap(getter, 1, "foo"); expectTypeOf<number>(value); expect(value).toBe(4); } + + { + // @ts-expect-error - invalid optional param type + unwrap(getter, 1, "foo", { y: "2" }); + } });examples/with-tailwindcss/src/app/page.tsx (1)
Line range hint
8-12: Consider documenting the different usage patterns.This file demonstrates multiple valid ways to use the endpoint prop (
useUploadThinghook,UploadButton, andUploadDropzone). Consider adding comments to explain these different usage patterns and their trade-offs, particularly regarding IDE support.Example documentation:
const { startUpload } = useUploadThing("videoAndImage", { + // Method 1: Using string literal - Simple but no "Go to definition" support onClientUploadComplete: () => { alert("Upload Completed"); }, }); // ... <UploadButton + // Method 1: Using string literal - Simple but no "Go to definition" support endpoint="videoAndImage" // ... /> <UploadDropzone + // Method 2: Using routeRegistry - Enables "Go to definition" IDE feature endpoint={(routeRegistry) => routeRegistry.videoAndImage} // ... />Also applies to: 19-24, 30-37
examples/minimal-solidstart/src/routes/index.tsx (2)
Line range hint
7-7: Consider using the callback style consistently for all endpoint specifications.The file demonstrates three different ways to specify endpoints:
createUploadThing("videoAndImage", ...)UploadButton endpoint="videoAndImage"UploadDropzone endpoint={(routeRegistry) => routeRegistry.videoAndImage}While the callback style (option 3) enables IDE's "Go to definition" feature, the string literal style (options 1 and 2) doesn't provide this functionality. For consistency and better developer experience, consider updating all instances to use the callback style.
Apply these changes:
- const { startUpload } = createUploadThing("videoAndImage", { + const { startUpload } = createUploadThing((routeRegistry) => routeRegistry.videoAndImage, {<UploadButton - endpoint="videoAndImage" + endpoint={(routeRegistry) => routeRegistry.videoAndImage}Also applies to: 43-43
Line range hint
8-10: Consider enhancing documentation comments to cover endpoint specification styles.The current documentation links are helpful but don't specifically highlight the different ways to specify endpoints. Consider adding a note about the benefits of using the callback style for better IDE support.
Add a comment like this before each component:
/** * @see https://docs.uploadthing.com/api-reference/react#uploaddropzone + * Note: Using the callback style for `endpoint` enables IDE's "Go to definition" feature + * whereas string literals don't provide this functionality. */Also applies to: 39-41
examples/with-drizzle-pagesdir/src/pages/index.tsx (1)
Line range hint
35-42: Consider updating UploadButton to use the function-based endpoint pattern.For consistency with
UploadDropzoneand to enable "Go to definition" support, consider updating theendpointprop here as well.- endpoint="videoAndImage" + endpoint={(routeRegistry) => routeRegistry.videoAndImage}examples/with-drizzle-appdir/src/app/uploader.tsx (2)
52-52: Consider updating UploadButton to use the same endpoint pattern.There's an inconsistency in how endpoints are specified between UploadButton and UploadDropzone. While UploadDropzone uses the new function-based approach that enables IDE navigation, UploadButton still uses the string literal approach.
Apply this change to maintain consistency:
- endpoint="videoAndImage" + endpoint={(routeRegistry) => routeRegistry.videoAndImage}Also applies to: 37-37
Line range hint
1-62: Consider showcasing all three usage patterns in the example.The PR objectives mention three different ways to use endpoints:
- Type-safe string literal
- Importing routeRegistry
- Callback argument (currently shown)
Consider expanding this example to demonstrate all three approaches, helping users understand the trade-offs between them.
Would you like me to provide an example that demonstrates all three usage patterns?
examples/minimal-tanstack-start/app/routes/index.tsx (2)
Line range hint
13-13: Consider usingrouteRegistryfor IDE navigation supportThe current string literal approach
"videoAndImage"doesn't support the "Go to definition" IDE feature. Consider using therouteRegistryapproach for consistency and better IDE support.- const { startUpload } = useUploadThing("videoAndImage", { + const { startUpload } = useUploadThing((routeRegistry) => routeRegistry.videoAndImage, {
Line range hint
36-36: Consider usingrouteRegistryfor IDE navigation supportThe current string literal approach
endpoint="videoAndImage"doesn't support the "Go to definition" IDE feature. Consider using therouteRegistryapproach for consistency and better IDE support.- endpoint="videoAndImage" + endpoint={(routeRegistry) => routeRegistry.videoAndImage}examples/backend-adapters/client-vanilla/src/resumable-upload.ts (1)
Line range hint
89-89: Consider updatingsetInputPropsto use callback styleFor consistency with the
createUploadchanges and to fully support "Go to definition", consider updating thesetInputPropscall to use the callback style:- setInputProps("videoAndImage", input); + setInputProps((routeRegistry) => routeRegistry.videoAndImage, input);packages/solid/src/create-uploadthing.ts (1)
121-122: LGTM: Endpoint unwrapping implementationThe endpoint unwrapping mechanism is correctly implemented and used consistently.
Consider enhancing the deprecation notice to explain why
routeConfigis preferred overpermittedFileInfo:/** - * @deprecated Use `routeConfig` instead + * @deprecated Use `routeConfig` instead as it provides the same functionality with better type safety and IDE support */ permittedFileInfo: routeConfigAlso applies to: 132-132
packages/vue/src/useUploadThing.ts (1)
64-67: Consider adding JSDoc for type inference.The type inference logic is correct, but could benefit from documentation explaining the conditional type behavior.
+/** + * Infers the input type for the endpoint. + * If the endpoint doesn't require input, the second argument is optional. + */ type InferredInput = inferEndpointInput<TRouter[TEndpoint]>; type FuncInput = undefined extends InferredInput ? [files: File[], input?: undefined] : [files: File[], input: InferredInput];packages/svelte/src/lib/create-uploadthing.ts (1)
Line range hint
97-102: Consider tracking the TODO for future API refactoring.The error handling looks robust, but there's a TODO comment indicating potential API refactoring in the next major version.
Would you like me to create a GitHub issue to track this TODO for future API improvements?
packages/react/src/useUploadThing.ts (1)
163-163: LGTM: Enhanced type safety for public functions.The changes correctly implement
EndpointArgtype for bothuseUploadThingandgetRouteConfigfunctions.Consider improving the error message handling in
getRouteConfig:- `No config found for endpoint "${endpoint.toString()}". Please make sure to use the NextSSRPlugin in your Next.js app.`, + `No config found for endpoint "${String(endpoint)}". Please make sure to use the NextSSRPlugin in your Next.js app.`,This change ensures consistent string conversion for all endpoint types.
Also applies to: 169-169, 171-171
packages/shared/src/utils.ts (3)
356-358: Add JSDoc documentation for the noop function.While the implementation is correct, adding documentation would help explain its purpose as a Proxy target.
+/** + * No-operation function used as a target for Proxy objects. + * @internal + */ export function noop() { // noop }
360-364: Add JSDoc documentation for the identity proxy creator.The implementation is correct and well-typed. Consider adding documentation to explain its purpose in supporting IDE features.
+/** + * Creates a Proxy that returns the accessed property name as a string. + * This enables IDE features like "Go to definition" by making string literals + * appear as property accesses. + * + * @example + * const registry = createIdentityProxy<Routes>(); + * const route = registry.someRoute; // Returns "someRoute" as a string + * + * @returns A proxy object that returns property names when accessed + */ export function createIdentityProxy<TObj extends Record<string, unknown>>() { return new Proxy(noop, { get: (_, prop) => prop, }) as unknown as TObj; }
366-371: Add documentation and parameter validation.The implementation is correct, but could benefit from documentation and defensive programming.
+/** + * Unwraps a value that could be either a direct value or a function returning that value. + * + * @example + * unwrap("direct value") // Returns: "direct value" + * unwrap((x) => x + 1, 1) // Returns: 2 + * + * @param x - The value or function to unwrap + * @param args - Arguments to pass if x is a function + * @returns The unwrapped value + */ export function unwrap<T extends Json | PropertyKey, Param extends unknown[]>( x: T | ((...args: Param) => T), ...args: Param ) { + if (args.length > 0 && typeof x !== "function") { + console.warn("Arguments provided but value is not a function"); + } return typeof x === "function" ? x(...args) : x; }docs/src/app/(docs)/api-reference/react/page.mdx (2)
215-231: Consider enhancing the example to show both endpoint usage patterns.The documentation clearly explains the new callback-based endpoint usage. However, the example could be more helpful by showing both approaches side by side:
- ```ts - await uploadFiles((routeRegistry) => routeRegistry.routeEndpoint, { ... }) - ``` + ```ts + // Using string literal (no "Go to Definition" support) + await uploadFiles("routeEndpoint", { ... }) + + // Using callback (enables "Go to Definition" support) + await uploadFiles((routeRegistry) => routeRegistry.routeEndpoint, { ... }) + ```
503-516: Update example code to demonstrate callback-based endpoint usage.The documentation explains the new callback-based endpoint usage, but the example code at the end of the file still uses the string literal approach.
- const { startUpload, routeConfig } = useUploadThing("myUploadEndpoint", { + const { startUpload, routeConfig } = useUploadThing( + (routeRegistry) => routeRegistry.myUploadEndpoint, + {Also applies to: 617-617
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (27)
- .changeset/twenty-rings-unite.md (1 hunks)
- docs/src/app/(docs)/api-reference/client/page.mdx (1 hunks)
- docs/src/app/(docs)/api-reference/react/page.mdx (3 hunks)
- examples/backend-adapters/client-react/src/main.tsx (1 hunks)
- examples/backend-adapters/client-vanilla/src/resumable-upload.ts (1 hunks)
- examples/minimal-appdir/src/app/page.tsx (2 hunks)
- examples/minimal-pagedir/src/pages/index.tsx (1 hunks)
- examples/minimal-solidstart/src/routes/index.tsx (1 hunks)
- examples/minimal-tanstack-start/app/routes/index.tsx (1 hunks)
- examples/with-clerk-appdir/src/app/page.tsx (1 hunks)
- examples/with-clerk-pagesdir/src/pages/index.tsx (1 hunks)
- examples/with-drizzle-appdir/src/app/uploader.tsx (1 hunks)
- examples/with-drizzle-pagesdir/src/pages/index.tsx (1 hunks)
- examples/with-novel/uploadthing/novel-plugin.ts (2 hunks)
- examples/with-tailwindcss/src/app/page.tsx (1 hunks)
- packages/react/src/useUploadThing.ts (7 hunks)
- packages/react/test/client-generator.test.ts (2 hunks)
- packages/react/test/upload-button.test.tsx (1 hunks)
- packages/shared/src/utils.ts (2 hunks)
- packages/shared/test/unwrap.test.ts (1 hunks)
- packages/solid/src/create-uploadthing.ts (4 hunks)
- packages/solid/src/types.ts (2 hunks)
- packages/svelte/src/lib/create-uploadthing.ts (5 hunks)
- packages/svelte/src/lib/types.ts (2 hunks)
- packages/uploadthing/test/client.test.ts (2 hunks)
- packages/vue/src/types.ts (2 hunks)
- packages/vue/src/useUploadThing.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- docs/src/app/(docs)/api-reference/client/page.mdx
- packages/react/test/client-generator.test.ts
- packages/uploadthing/test/client.test.ts
🧰 Additional context used
🪛 LanguageTool
.changeset/twenty-rings-unite.md
[grammar] ~12-~12: The plural noun “places” expects the verb form “accept”.
Context: ...rts "Go to Definition" All places that accepts theendpointargument now additionall...(NNS_THAT_VBZ)
[uncategorized] ~12-~12: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...heendpointargument now additionally accepts a function that gets a route registry a...(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)
🪛 Biome
packages/shared/test/unwrap.test.ts
[error] 25-32: This block statement doesn't serve any purpose and can be safely removed.
Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.(lint/complexity/noUselessLoneBlockStatements)
🔇 Additional comments (44)
.changeset/twenty-rings-unite.md (2)
1-8: LGTM: Version bumps are appropriate.The minor version bumps across all packages are appropriate for this new feature addition, following semantic versioning principles.
16-34: LGTM: Clear and comprehensive examples.The examples effectively demonstrate the three different usage patterns of the new feature across different contexts:
- Direct client usage with
uploadFiles- React hook usage with
useUploadThing- Component usage with
UploadButtonThe consistent pattern of using
(routeRegistry) => routeRegistry.videoAndImagemakes it clear how to implement the "Go to Definition" feature.examples/minimal-pagedir/src/pages/index.tsx (1)
36-36: LGTM! Demonstrates the new "Go to definition" feature.This is a good example of using the new function-based endpoint pattern that enables IDE "Go to definition" support.
examples/with-clerk-appdir/src/app/page.tsx (1)
29-29: LGTM! Successfully implements "Go to definition" support.The change from string literal to callback-based endpoint specification enables IDE navigation to symbol definition, which is the primary goal of this PR.
examples/backend-adapters/client-react/src/main.tsx (1)
27-27: LGTM! Successfully implements IDE "Go to definition" supportThe new endpoint implementation using
routeRegistryenables IDE navigation to symbol definitions while maintaining type safety.examples/with-clerk-pagesdir/src/pages/index.tsx (1)
30-30:⚠️ Potential issueEnsure consistent endpoint prop usage across components.
While the
UploadDropzonecomponent now uses the new function-based approach for better IDE support, theUploadButtoncomponent still uses the string literal approach. Consider updating both components to use the same pattern for consistency.Apply this diff to make the components consistent:
- endpoint="videoAndImage" + endpoint={(routeRegistry) => routeRegistry.videoAndImage}Let's verify the implementation pattern across the codebase:
packages/shared/test/unwrap.test.ts (3)
1-3: LGTM! Well-structured imports.The imports include all necessary testing utilities, including
expectTypeOffor type checking, which is crucial for this type-safety focused feature.
5-10: LGTM! Good baseline test coverage.The test effectively validates both type safety and runtime behavior for the basic case of unwrapping a direct value.
19-33: LGTM! Comprehensive type checking.The test provides excellent coverage including type-error cases. The standalone block at lines 25-32, while flagged by static analysis, serves a valid purpose for isolating type-checking assertions.
Let's verify if similar type-checking patterns exist elsewhere in the codebase:
✅ Verification successful
Based on the search results, I can now generate the final response as I have sufficient information to verify the review comment's concern about type-checking patterns.
Type-checking pattern is consistent with codebase practices
The standalone block with
@ts-expect-errorannotations inunwrap.test.tsfollows a well-established pattern throughout the codebase for testing type errors. Similar patterns are found in:
- Test files like
gen-uploader.test.ts,upload-builder.test.ts, andclient-generator.test.ts- Component files where type assertions are necessary but validated elsewhere
- API and utility files where certain type constraints need to be bypassed with proper documentation
The block's usage serves its purpose effectively and maintains consistency with the codebase's type-checking practices.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for similar type-checking patterns using @ts-expect-error rg "@ts-expect-error" -A 2 -B 2Length of output: 21299
🧰 Tools
🪛 Biome
[error] 25-32: This block statement doesn't serve any purpose and can be safely removed.
Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.(lint/complexity/noUselessLoneBlockStatements)
examples/with-tailwindcss/src/app/page.tsx (1)
30-30: LGTM! Enhanced IDE support added.The function-based endpoint definition enables the "Go to definition" IDE feature, improving code navigation and developer experience.
examples/with-novel/uploadthing/novel-plugin.ts (2)
30-35: LGTM! Enhanced IDE support for endpoint resolution.The change from string literal to callback-based endpoint resolution enables IDE features like "Go to definition" while maintaining type safety.
53-55: LGTM! Consistent implementation of endpoint resolution.The change maintains consistency with the uploadFiles implementation above, preserving type safety while enabling IDE navigation features.
Let's verify that all endpoint string literals have been updated to use the callback pattern:
✅ Verification successful
Based on the search results, I can now generate the final response:
All endpoint resolutions have been consistently updated to use the callback pattern
The search results confirm that all direct usages of
uploadFilesandgetRouteConfigin the codebase have been updated to use the callback pattern for endpoint resolution. The examples found in the codebase show consistent usage:
- In documentation:
uploadFiles((routeRegistry) => routeRegistry.routeEndpoint, { ... })- In tests:
uploadFiles((routeRegistry) => routeRegistry.foo, { files: [file] })- In the Novel plugin: Both
uploadFilesandgetRouteConfiguse the callback pattern with(routeRegistry) => routeRegistry.imageUploader🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for any remaining string literal endpoints that might need updating # Expect: No direct string literals used with uploadFiles or getRouteConfig rg -A 2 'uploadFiles\(' rg -A 2 'getRouteConfig\('Length of output: 18554
examples/with-drizzle-pagesdir/src/pages/index.tsx (1)
51-51: LGTM! Function-based endpoint enables "Go to definition" support.The change from string literal to function-based endpoint improves IDE support by making the
videoAndImagesymbol navigable.examples/minimal-appdir/src/app/page.tsx (2)
35-35: LGTM! Implements IDE-friendly endpoint definition.The callback-style endpoint definition enables the "Go to definition" IDE feature while maintaining type safety.
49-49: LGTM! Maintains consistency with UploadButton implementation.The endpoint definition now matches the UploadButton style, addressing the consistency concern from previous reviews while enabling IDE features.
examples/with-drizzle-appdir/src/app/uploader.tsx (1)
52-52: LGTM! The new endpoint specification enables IDE navigation.The change from a string literal to a function-based approach allows IDEs to provide "Go to definition" support, which aligns with the PR objectives.
Let's verify the endpoint specification is correctly typed:
✅ Verification successful
Based on the shell script results, I can now generate the final response since I have enough information about how the endpoint specification and type system works in the codebase.
The new endpoint specification is correctly typed and safe to use
The endpoint specification using
(routeRegistry) => routeRegistry.videoAndImageis properly typed because:
- The
routeRegistryobject is created bygenUploaderinternally (seepackages/uploadthing/src/client.tswherecreateIdentityProxyis used)- The type information flows through
generateReactHelpers(from@uploadthing/react) which is used to create the components- The endpoint specification pattern is consistent with the documented API and examples throughout the codebase
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check if routeRegistry type is properly imported and used # Expected: Should find the type definition and its usage # Search for routeRegistry type definition ast-grep --pattern 'type $routeRegistry = { $$$' # Search for generateReactHelpers or genUploader usage which should provide the type rg -A 5 'generateReactHelpers|genUploader'Length of output: 36655
examples/minimal-tanstack-start/app/routes/index.tsx (2)
53-53: LGTM! Proper implementation of therouteRegistryapproachThe implementation correctly uses the function-based approach with
routeRegistry, enabling the "Go to definition" IDE feature as intended.
53-53: Verify consistent usage of thevideoAndImageendpointLet's verify that this endpoint identifier is consistently used across the codebase.
✅ Verification successful
Based on the search results, I can now generate the final response as I have sufficient information about the usage of the
videoAndImageendpoint across the codebase.The
videoAndImageendpoint usage is consistent across the codebaseThe endpoint is used consistently throughout the codebase in two equivalent patterns:
- Direct string usage:
endpoint="videoAndImage"- Route registry usage:
endpoint={(routeRegistry) => routeRegistry.videoAndImage}Both patterns are valid and refer to the same endpoint. The implementation in the file under review follows the route registry pattern, which is consistently used across multiple examples including minimal-appdir, minimal-pagedir, and various integration examples (with-clerk, with-drizzle, etc.).
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for consistent usage of the videoAndImage endpoint # Expected: Find all occurrences to verify consistent naming and usage echo "Searching for string literal usage:" rg '"videoAndImage"' -A 2 echo -e "\nSearching for routeRegistry usage:" rg 'routeRegistry\.videoAndImage' -A 2Length of output: 10552
examples/backend-adapters/client-vanilla/src/resumable-upload.ts (1)
39-39: LGTM: Successfully implements "Go to definition" supportThe change from string literal to callback-based endpoint specification enables IDE navigation to symbol definitions while maintaining type safety.
packages/vue/src/types.ts (2)
10-10: LGTM: Import addition supports IDE features.The addition of
EndpointArgtype import aligns with the PR's objective to support the "Go to definition" IDE feature.
114-114: LGTM: Enhanced type definition enables IDE navigation.The update to use
EndpointArg<TRouter, TEndpoint>enables IDE "Go to definition" functionality while maintaining type safety. This change successfully implements the core feature of this PR.Let's verify that this type is consistently used across the codebase:
✅ Verification successful
Let me try a different approach to verify the usage of
EndpointArgtype in the codebase.This will help us understand:
- All occurrences of EndpointArg in the codebase
- How it's defined and used in type definitions
- Context around its usage
Based on the search results, I can now provide a final response:
Verified: EndpointArg type is consistently used across all framework implementations
The type
EndpointArg<TRouter, TEndpoint>is correctly and consistently implemented across the entire codebase:
- Used in core
uploadthingpackage where it's defined- Consistently imported and used in all framework implementations:
- Vue (
packages/vue/src/types.ts)- React (
packages/react/src/types.ts)- Svelte (
packages/svelte/src/lib/types.ts)- Solid (
packages/solid/src/types.ts)Each implementation follows the same pattern for type safety and IDE navigation support, confirming this is a well-implemented cross-framework feature.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify consistent usage of EndpointArg type # Test: Search for EndpointArg usage in type definitions ast-grep --pattern 'endpoint: EndpointArg<$_, $_>'Length of output: 52
Script:
#!/bin/bash # Search for any usage of EndpointArg type rg "EndpointArg" -A 2 -B 2 # Also check type definitions and imports ast-grep --pattern 'type EndpointArg'Length of output: 8223
packages/solid/src/create-uploadthing.ts (4)
6-6: LGTM: Import additions support IDE featuresThe new imports enable the endpoint unwrapping mechanism required for "Go to definition" functionality.
Also applies to: 13-13
40-43: LGTM: Enhanced genUploader usage enables IDE featuresThe addition of
routeRegistrydestructuring is key to enabling the "Go to definition" functionality, working in conjunction with the endpoint unwrapping mechanism.
53-56: LGTM: Type inference maintains safetyThe type inference changes correctly handle both required and optional input cases while working with the new endpoint system.
46-47: Verify the usage of EndpointArg typeThe type enhancement correctly supports both string literals and registry keys, enabling IDE features while maintaining type safety.
✅ Verification successful
Let me try a different approach to verify the usage of
EndpointArgtype.The previous command failed because the typescript file type wasn't recognized. The new command adds typescript file type explicitly and searches for any occurrence of
EndpointArgwith context. This will help us verify its definition and usage across the codebase.
Based on the search results, I can now generate the final response as we have comprehensive information about the
EndpointArgtype usage across the codebase.The EndpointArg type is consistently used across all framework packages
The type enhancement is correctly implemented and consistently used across the entire codebase:
- Defined in
packages/uploadthing/src/types.ts- Consistently used in all framework packages (react, vue, svelte, solid) with the same generic parameters
<TRouter, TEndpoint>- Applied uniformly in component props and hook parameters
- Maintains type safety across the entire library ecosystem
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify consistent usage of EndpointArg type across the codebase # Expect: Similar type usage in other packages (react, vue, svelte) rg -t typescript "EndpointArg.*TRouter.*TEndpoint"Length of output: 87
Script:
#!/bin/bash # Search for EndpointArg type definition and usage rg --type-add 'ts:*.{ts,tsx}' -t ts "EndpointArg" -A 2 # Also check for files that might use this type fd -e ts -e tsx --exec grep -l "EndpointArg"Length of output: 4967
packages/svelte/src/lib/types.ts (2)
10-10: LGTM: Import addition supports new type system.The addition of
EndpointArgimport aligns with the PR's objective to support IDE "Go to definition" feature.
114-114: LGTM: Enhanced type safety for endpoint property.The update to use
EndpointArg<TRouter, TEndpoint>instead ofTEndpointenables IDE "Go to definition" functionality while maintaining type safety. This change is consistent with similar updates in the React and Vue packages.packages/vue/src/useUploadThing.ts (4)
8-8: LGTM: Import additions support the new endpoint handling.The new imports enable the flexible endpoint specification required for IDE "Go to definition" support.
Also applies to: 14-14
56-59: LGTM: Enhanced endpoint type supports IDE navigation.The
EndpointArgtype now supports three ways to specify the endpoint while maintaining type safety:
- String literal (original behavior)
- routeRegistry symbol (enables "Go to definition")
- Callback for dynamic access
131-132: LGTM: Proper endpoint resolution with reactive updates.The computed property correctly unwraps the endpoint while maintaining Vue's reactivity system.
#!/bin/bash # Verify unwrap function implementation ast-grep --pattern 'function unwrap($_) { $$$ }'Also applies to: 142-142
51-54: LGTM: Correctly retrieves routeRegistry for endpoint resolution.The destructuring of
routeRegistryalongsideuploadFilesenables the IDE navigation feature while maintaining existing functionality.✅ Verification successful
Let me try a different approach to verify the
genUploaderimplementation.This will help us verify:
- The actual implementation of genUploader
- How it's exported and what it returns
- The type definition that should show if routeRegistry is part of the return type
From the results, I can see the
genUploaderimplementation inpackages/uploadthing/src/client.tswhich shows thatrouteRegistryis indeed created usingcreateIdentityProxy. Let me verify the complete implementation and return type with another search.
Based on the results, I can now generate the final response as we have sufficient evidence:
Verified: The destructuring of
routeRegistryfromgenUploaderis correct and type-safeThe implementation in
packages/uploadthing/src/client.tsconfirms that:
genUploadercreates and returnsrouteRegistryusingcreateIdentityProxyRouteRegistrytype is properly defined inpackages/uploadthing/src/types.ts- The usage in Vue package matches the implementation's contract
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify genUploader implementation returns routeRegistry ast-grep --pattern 'const { uploadFiles, routeRegistry } = genUploader'Length of output: 146
Script:
#!/bin/bash # Search for genUploader implementation ast-grep --pattern 'function genUploader($_) { $$$ }' # Also search for any exports of genUploader rg "export.*genUploader" -A 5 # Look for the type definition or interface of genUploader's return type rg "interface.*Upload" -A 10Length of output: 6038
Script:
#!/bin/bash # Get the full implementation of genUploader from client.ts rg -A 20 "export const genUploader = " packages/uploadthing/src/client.ts # Look for createIdentityProxy implementation ast-grep --pattern 'function createIdentityProxy($_) { $$$ }' # Search for RouteRegistry type definition rg "type.*RouteRegistry" -A 5Length of output: 994
packages/svelte/src/lib/create-uploadthing.ts (5)
7-7: LGTM: Import changes align with the PR objective.The addition of
unwrapand new type imports supports the implementation of the "Go to definition" feature by providing the necessary type information and endpoint handling utilities.Also applies to: 13-17
44-47: LGTM: Proper extraction of routeRegistry.The destructuring of
routeRegistryfromgenUploaderis essential for enabling the "Go to definition" feature by providing access to endpoint definitions.
50-51: LGTM: Enhanced type safety for endpoint and input handling.The changes improve type safety by:
- Using
EndpointArgto support both string literals and registry-based endpoints- Adding proper type inference for input parameters
Also applies to: 57-60
144-146: LGTM: Consistent type safety in generateUploader.The endpoint type enhancement matches the changes in useUploadThing, ensuring consistent type safety across the API.
124-125: Verify endpoint unwrapping behavior.The endpoint unwrapping logic looks correct, but we should verify that it handles all possible endpoint argument types as specified in the PR objectives.
Also applies to: 135-135
✅ Verification successful
Let me try a different approach to verify the endpoint unwrapping behavior.
Let me try one more approach focusing on the unwrap implementation and its tests.
Based on the test implementation and source code we found, I can now provide a final response.
The endpoint unwrapping behavior is correctly implemented and well-tested
The
unwrapfunction implementation inpackages/shared/src/utils.tsand its comprehensive test suite inpackages/shared/test/unwrap.test.tsdemonstrate that it properly handles all possible endpoint argument types:
- Direct values (string literals)
- Functions with no arguments
- Functions with one argument
- Functions with multiple arguments
- Functions with optional arguments
The implementation
typeof x === "function" ? x(...args) : xcorrectly handles both direct values and callback functions, with proper type checking as verified by the test cases.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all three usage methods of endpoints are supported # 1. String literal # 2. routeRegistry import # 3. Callback argument # Search for endpoint usage patterns echo "Searching for endpoint usage patterns..." rg -t typescript -t javascript 'useUploadThing\(' -A 3Length of output: 182
Script:
#!/bin/bash # Let's first check the implementation of the unwrap function echo "Checking unwrap function implementation:" rg -A 10 "function unwrap" packages/svelte/src/lib/create-uploadthing.ts # Let's also look for test files that might show usage patterns echo -e "\nSearching for test files:" fd -e test.ts -e spec.ts -e test.js -e spec.js # Let's examine any example files that might demonstrate usage echo -e "\nSearching for example files:" fd -e example.ts -e example.js # Let's also check for documentation or type definitions echo -e "\nChecking type definitions:" rg -t typescript "type.*Endpoint" packages/svelte/src/Length of output: 1203
Script:
#!/bin/bash # Let's examine the unwrap test file we found echo "Checking unwrap test implementation:" cat packages/shared/test/unwrap.test.ts # Let's also look at the actual unwrap implementation in the shared package echo -e "\nLooking for unwrap implementation in shared package:" rg -g '!*.test.ts' -g '!*.spec.ts' -A 10 "function unwrap" packages/shared/src/ # Let's check for type definitions of endpoint in the shared package echo -e "\nChecking endpoint types in shared:" rg -g '!*.test.ts' -g '!*.spec.ts' "type.*Endpoint" packages/shared/src/Length of output: 2336
packages/solid/src/types.ts (2)
10-10: LGTM: Import addition supports new endpoint definition feature.The addition of
EndpointArgtype import aligns with the PR's objective to support IDE "Go to definition" functionality.
123-123: LGTM: Enhanced type definition enables flexible endpoint usage.The change from
TEndpointtoEndpointArg<TRouter, TEndpoint>successfully implements the three usage methods mentioned in the PR objectives:
- Type-safe string literal
- Imported
routeRegistry- Callback argument
This change maintains type safety while enabling IDE "Go to definition" support.
packages/react/src/useUploadThing.ts (4)
10-10: LGTM: New imports support the Go-to-definition feature.The addition of
unwrapandEndpointArgaligns with the PR objective to support IDE's Go-to-definition functionality.Also applies to: 20-20
57-57: LGTM: Enhanced type safety for endpoint handling.The changes improve type safety by:
- Using
EndpointArgtype for the endpoint parameter- Correctly resolving the endpoint using
unwrapwith therouteRegistryAlso applies to: 60-60, 136-137
157-160: LGTM: Proper initialization and exposure of client helpers.The
clientHelpersinitialization is correctly placed to ensure therouteRegistryis available for endpoint resolution, and all helpers are properly exposed via the spread operator.Also applies to: 183-183
57-57: Verify handling of all endpoint types.The implementation supports three different usage methods as mentioned in the PR objectives. Let's verify that all endpoint types are handled correctly:
- Type-safe string literal
routeRegistrysymbol- Callback argument
Also applies to: 163-163, 169-169
✅ Verification successful
Let me try a different approach to verify the endpoint types handling by examining the implementation and type definitions.
Let me try one more search with a broader pattern to find the type definitions and implementations.
Based on the type definitions found, I can now generate the final response.
All endpoint types are properly handled through type definitions
The type system correctly handles all three endpoint specification methods:
- String literal through direct
TEndpointtyperouteRegistrysymbol through theRouteRegistry<TRouter>mapped type- Callback argument through the function type
(_: RouteRegistry<TRouter>) => TEndpointThe
EndpointArgtype definition uses a union type to accommodate all these cases:type EndpointArg<TRouter extends FileRouter, TEndpoint extends keyof TRouter> = TEndpoint | ((_: RouteRegistry<TRouter>) => TEndpoint);🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for test cases covering different endpoint types rg -A 5 "useUploadThing\(" test/Length of output: 80
Script:
#!/bin/bash # Search for type definitions and implementations related to endpoint handling rg -A 10 "type\s+EndpointArg" packages/ rg -A 10 "type\s+RouteRegistry" packages/ # Look for actual usage examples in the codebase rg -A 5 "useUploadThing" packages/Length of output: 120
Script:
#!/bin/bash # Search for the type definitions in the TypeScript files fd -e ts -e tsx -x cat {} \; | rg -A 10 "type\s+(EndpointArg|RouteRegistry)" # Look for the implementation of useUploadThing ast-grep --pattern 'export function useUploadThing$_($$$) { $$$ }'Length of output: 749
packages/shared/src/utils.ts (1)
20-20: LGTM: Type import is correctly placed.The
Jsontype import is appropriately added to support the newunwrapfunction's type constraints.docs/src/app/(docs)/api-reference/react/page.mdx (1)
371-387: Documentation looks good!The endpoint prop documentation is consistent with the UploadButton component.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Go to definition á la trpc is nice
CleanShot.2024-10-11.at.20.28.34.mp4
This allows 3 different ways:
Summary by CodeRabbit
Release Notes
New Features
configproperty toUploadthingComponentPropsfor customizable upload behavior.Bug Fixes
Documentation
generateComponentsin favor ofgenerateUploadButtonandgenerateUploadDropzone.Tests