Skip to content

feat: support IDE feature Go to defintion - #1008

Merged
juliusmarminge merged 13 commits into
mainfrom
routeRegistry
Oct 23, 2024
Merged

juliusmarminge merged 13 commits into
mainfrom
routeRegistry

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Oct 11, 2024 •

Copy link
Copy Markdown
Member

Go to definition á la trpc is nice

CleanShot.2024-10-11.at.20.28.34.mp4

This allows 3 different ways:

// 1. As today, just a typesafe string literal. DOES NOT PROVIDE GO TO DEFINITION
useUploadThing("videoAndImage", { ... })

// 2. import routeRegistry returned from `genUploader` / `generateReactHelpers`
import { routeRegistry } from "~/utils/uploadthing";

useUploadThing(routeRegistry.videoAndImage, { ... })

// 3. As a callback argument
useUploadThing(
  (_) => _.videoAndImage,
  {
    onClientUploadComplete: () => { ... }
  }
)

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced flexibility for defining endpoints using functions that reference a route registry across various components and methods.
    • Added optional config property to UploadthingComponentProps for customizable upload behavior.
  • Bug Fixes

    • Improved type safety in endpoint definitions and handling within the upload functionality.
  • Documentation

    • Updated API documentation to reflect new endpoint handling and usage patterns.
    • Deprecated generateComponents in favor of generateUploadButton and generateUploadDropzone.
  • Tests

    • Introduced new test cases to validate the functionality of components with the updated endpoint handling.

@vercel

vercel Bot commented Oct 11, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 8:50am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Visit Preview Oct 23, 2024 8:50am

@changeset-bot

changeset-bot Bot commented Oct 11, 2024 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b132bf9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
uploadthing Minor
@uploadthing/shared Minor
@uploadthing/svelte Minor
@uploadthing/react Minor
@uploadthing/solid Minor
@uploadthing/vue Minor
@uploadthing/expo Patch
@uploadthing/nuxt Patch

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

@coderabbitai

coderabbitai Bot commented Oct 11, 2024 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request introduce new type definitions and enhance existing ones across various files, primarily focusing on the Endpoint and EndpointArg types. The modifications improve type safety and flexibility in how endpoints are specified in components and functions related to file uploads. Additionally, documentation updates clarify the usage of new features, and test cases are added to validate the functionality of these enhancements.

Changes

File Change Summary
packages/react/src/types.ts Added new type Endpoint<TRouter, TEndpoint>, updated UploadthingComponentProps to use Endpoint, and added optional config property.
packages/react/src/useUploadThing.ts Updated __useUploadThingInternal and useUploadThing to use EndpointArg for the endpoint parameter, improved internal logic for endpoint resolution.
packages/uploadthing/src/client.ts Added createIdentityProxy, updated genUploader to return routeRegistry, and modified parameter types for controllableUpload and typedUploadFiles.
packages/uploadthing/src/types.ts Introduced new types EndpointArg and RouteRegistry.
packages/react/test/client-generator.test.ts Added a new test case to verify functionality with a go-to-definition proxy as an endpoint argument.
packages/uploadthing/test/client.test.ts Updated test cases to use functions for endpoint retrieval instead of static strings.
docs/src/app/(docs)/api-reference/client/page.mdx Enhanced documentation for uploadFiles and createUpload, detailing new capabilities and parameters.
docs/src/app/(docs)/api-reference/react/page.mdx Updated documentation to deprecate generateComponents, introduced generateUploadButton and generateUploadDropzone, and updated component prop types.
examples/backend-adapters/client-react/src/main.tsx Changed UploadDropzone endpoint prop from static string to a function retrieving the endpoint from routeRegistry.
examples/minimal-appdir/src/app/page.tsx Updated UploadButton and UploadDropzone components to use function-based endpoint retrieval.
examples/minimal-pagedir/src/pages/index.tsx Modified UploadDropzone endpoint prop to use a function instead of a static string.
examples/minimal-solidstart/src/routes/index.tsx Updated UploadDropzone component's endpoint prop to a function accessing routeRegistry.
examples/with-clerk-appdir/src/app/page.tsx Changed UploadDropzone endpoint prop from string to a function that retrieves the endpoint from routeRegistry.
examples/with-drizzle-appdir/src/app/uploader.tsx Updated UploadDropzone endpoint prop to use a function for dynamic endpoint retrieval.
packages/shared/src/utils.ts Added new utility functions: noop, createIdentityProxy, and unwrap, alongside a new type alias Json.
packages/solid/src/create-uploadthing.ts Enhanced createUploadThing method to use EndpointArg for endpoint parameter and updated internal logic for endpoint handling.
packages/vue/src/types.ts Updated UploadthingComponentProps to use EndpointArg for the endpoint property and marked skipPolling as deprecated.

Possibly related PRs

Suggested reviewers

  • markflorkowski
  • t3dotgg

🐰 In the meadow where changes bloom,
New types emerge, dispelling gloom.
Endpoints now dance with grace and flair,
Uploads are smoother, handled with care.
With tests to guard and docs that shine,
A hop towards better, all is fine! 🌼✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bf04779 and b132bf9.

📒 Files selected for processing (1)
  • .changeset/twenty-rings-unite.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/twenty-rings-unite.md

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions

github-actions Bot commented Oct 11, 2024 •

Copy link
Copy Markdown
Contributor

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 26.11KB See Treemap 📊
PR (030b6e7) 26.32KB See Treemap 📊
Diff ↑220.00B

@pkg-pr-new

pkg-pr-new Bot commented Oct 11, 2024 •

Copy link
Copy Markdown

Open in Stackblitz

More templates

@uploadthing/nuxt

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/nuxt@1008

@uploadthing/react

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/react@1008

@uploadthing/shared

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/shared@1008

@uploadthing/solid

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/solid@1008

@uploadthing/svelte

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/svelte@1008

@uploadthing/vue

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/vue@1008

uploadthing

pnpm add https://pkg.pr.new/pingdotgg/uploadthing@1008

commit: b132bf9

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 routeRegistry to the exported members from generateReactHelpers is 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 routeRegistry in 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 routeRegistry to the exports enhances the file's utility without compromising its clarity or focus. The consistent use of the OurFileRouter type across exports maintains type safety.

As the project evolves, consider:

  1. Documenting the purpose and usage of routeRegistry for other developers.
  2. Ensuring that the OurFileRouter type definition (imported from "~/server/uploadthing") remains up-to-date with any changes to the upload functionality.
  3. 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 the UploadDropzone component.

To fully achieve the PR's goals:

  1. Update the UploadDropzone component to use routeRegistry.videoAndImage.
  2. 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: routeRegistry export and documentation.

The addition of routeRegistry to 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 @example section 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 routeRegistry feature 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 routeRegistry creation 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

📥 Commits

Files that changed from the base of the PR and between eba5f69 and 21d158f.

📒 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 of routeRegistry in the project.

The addition of routeRegistry to the exported members is a good enhancement. To ensure it's being utilized effectively:

  1. Check if routeRegistry is imported and used in other parts of the project.
  2. Verify that any existing usage of useUploadThing remains unaffected.

Run the following script to check the usage of routeRegistry and useUploadThing:

This script will help identify any potential issues or areas that might need updates following this change.

✅ Verification successful

Usage of routeRegistry and useUploadThing Verified Successfully.

The addition of routeRegistry has 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 routeRegistry to 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 in useUploadThing hook.

The change from a string literal to routeRegistry.videoAndImage enhances 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 RouteRegistry type is a well-implemented mapped type that should enhance type safety when working with routes defined in the FileRouter. 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 RouteRegistry will 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 RouteRegistry type 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! RouteRegistry is utilized in useUploadThing.ts to 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 the routeRegistry feature.

The addition of createIdentityProxy and RouteRegistry imports are necessary for implementing the new routeRegistry feature. This change enhances type safety and IDE integration for backend route definitions.

Also applies to: 23-23


174-175: LGTM: routeRegistry implementation supports IDE "Go to definition" feature.

The addition of routeRegistry using createIdentityProxy is 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: noop function implementation

The 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 objectives

The addition of noop and createIdentityProxy functions 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 noop function is a standard no-operation utility that can be used in various contexts. The createIdentityProxy function, 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: createIdentityProxy function

The createIdentityProxy function 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: createIdentityProxy function usage clarified

The createIdentityProxy function is utilized to create the routeRegistry object, 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 ts

Length 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 5

Length of output: 474

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
packages/react/src/types.ts (1)

30-33: LGTM: New Endpoint type enhances flexibility

The new Endpoint type and its usage in UploadthingComponentProps improve 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 Endpoint type for better documentation.

You could add a comment like this above the Endpoint type 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 with routeRegistry.

The routeRegistry is correctly added to the return object of genUploader. 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

📥 Commits

Files that changed from the base of the PR and between 21d158f and c2cd423.

📒 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 RouteRegistry

The addition of RouteRegistry import is consistent with the PR objective and necessary for the new Endpoint type definition.


Line range hint 1-155: Summary: Changes enhance type safety and flexibility

The modifications to this file, including the new Endpoint type 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 createIdentityProxy import from "@uploadthing/shared" is correctly placed with other imports from the same package. This import is necessary for the new routeRegistry functionality.


28-28: LGTM: New type import added correctly.

The RouteRegistry type import from "./types" is correctly placed with other type imports from the same file. This type is necessary for the new routeRegistry functionality.


270-270: LGTM: routeRegistry created correctly.

The routeRegistry object is correctly created using createIdentityProxy<RouteRegistry<TRouter>>(). This implementation supports the new IDE "Go to definition" feature for backend route definitions.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 comment

The 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 handling

This 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:

  1. Consider adding a type annotation for the rr parameter to ensure type safety:

    (rr: { videoAndImage: unknown }) => rr.videoAndImage
  2. Verify that the rr object 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 configurability

The changes to the UploadthingComponentProps type are well-implemented:

  1. The endpoint property now uses EndpointArg<TRouter, TEndpoint>, which enhances type safety and flexibility.
  2. The new config property 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 mode and appendOnPaste options in the config property to provide more clarity on their usage and effects.

packages/uploadthing/src/types.ts (1)

168-170: LGTM: RouteRegistry type enhances type safety.

The RouteRegistry type 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.withFooInput and (rr) => rr.exampleRoute as arguments to useUploadThing. 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

📥 Commits

Files that changed from the base of the PR and between c2cd423 and b258103.

📒 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.videoAndImage instead of the string literal "videoAndImage" is a great enhancement. This change:

  1. Enables the "Go to definition" IDE feature, improving code navigation.
  2. Provides better type safety by using the routeRegistry object.
  3. Maintains the existing functionality while improving the developer experience.

The rest of the uploadFiles call remains unchanged, ensuring that the current behavior is preserved.

packages/react/src/types.ts (2)

10-10: LGTM: New import enhances type safety

The addition of the EndpointArg import from uploadthing/types is a good improvement. It likely provides more flexibility and type safety for endpoint definitions in the UploadthingComponentProps type.


Line range hint 1-138: Summary: Improved type safety and configurability

The changes in this file significantly enhance the type definitions for the UploadThing library:

  1. The introduction of the EndpointArg type improves type safety for endpoint definitions.
  2. The updates to UploadthingComponentProps provide 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: New EndpointArg type aligns with PR objectives.

The new EndpointArg type effectively supports multiple usage methods for the useUploadThing function, 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 EndpointArg and RouteRegistry types 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 useUploadThing function, 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 importing describe.

The import statement has been updated to include describe from "vitest". However, describe is not used in the visible changes of this file. Please ensure that describe is 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 support

The change from using a string literal to a callback function (rr) => rr.foo is 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 case

This change maintains consistency with the previous update, using the callback syntax (rr) => rr.foo for 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 changes

The updates to this test file consistently implement the new callback syntax for specifying routes in uploadFiles function 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 new createUpload function!

The documentation for the createUpload function 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 isValidSize and isValidType functions 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 uploadFiles or createUpload functions 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 the UploadButton properties!

The new properties onUploadAborted, disabled, and config.cn significantly 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 onUploadAborted callback in the documentation to help developers understand its practical application.

Also applies to: 275-277, 287-290


Line range hint 387-389: Inconsistency in endpoint property type for UploadDropzone

While the additions of onUploadAborted, disabled, and config.cn properties are great and maintain consistency with the UploadButton component, there's an inconsistency in the endpoint property type. The UploadDropzone still uses keyof FileRouter instead of EndpointArg<FileRouter> as updated in the UploadButton component.

Update the endpoint property type for UploadDropzone to match the UploadButton:

- <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 endpoint argument as provided in the UploadButton documentation.

Also applies to: 451-453, 463-466


Line range hint 495-497: Excellent updates to the useUploadThing hook!

The addition of the signal parameter and onUploadAborted callback greatly improves the hook's flexibility in handling upload cancellations. The deprecation of permittedFileTypes in favor of the more comprehensive routeConfig is a good move towards providing more detailed configuration information.

Consider adding a brief example of how to use the new signal parameter and onUploadAborted callback 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 features

The provided example effectively demonstrates the integration of useDropzone and useUploadThing hooks, including the usage of the new routeConfig property. However, it doesn't showcase the newly added upload cancellation feature.

Consider enhancing the example to demonstrate how to use the signal parameter for upload cancellation. This could include:

  1. Creating an AbortController
  2. Passing its signal to the useUploadThing hook
  3. 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

📥 Commits

Files that changed from the base of the PR and between b258103 and 70aa9fc.

📒 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 for generateClientDropzoneAccept function.

The documentation for the generateClientDropzoneAccept function 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 generateMimeTypes and generatePermittedFileTypes functions 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 the endpoint property documentation!

The change from keyof FileRouter to EndpointArg<FileRouter> for the endpoint property 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 useUploadThing hook is using a string literal "videoAndImage" which doesn't support the new "Go to definition" IDE feature. Consider updating to use the routeRegistry pattern for consistency with the UploadDropzone component.

- 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 UploadButton component is using a string literal endpoint which doesn't support "Go to definition". Consider updating this to use the routeRegistry pattern 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:

  1. Type-safe string literal
  2. Importing routeRegistry
  3. 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:

  1. String literal (UploadButton): endpoint="videoAndImage"
  2. 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 pattern

The UploadButton is still using a string literal for the endpoint while UploadDropzone uses 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 (useUploadThing hook, UploadButton, and UploadDropzone). 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:

  1. createUploadThing("videoAndImage", ...)
  2. UploadButton endpoint="videoAndImage"
  3. 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 UploadDropzone and to enable "Go to definition" support, consider updating the endpoint prop 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:

  1. Type-safe string literal
  2. Importing routeRegistry
  3. 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 using routeRegistry for IDE navigation support

The current string literal approach "videoAndImage" doesn't support the "Go to definition" IDE feature. Consider using the routeRegistry approach for consistency and better IDE support.

- const { startUpload } = useUploadThing("videoAndImage", {
+ const { startUpload } = useUploadThing((routeRegistry) => routeRegistry.videoAndImage, {

Line range hint 36-36: Consider using routeRegistry for IDE navigation support

The current string literal approach endpoint="videoAndImage" doesn't support the "Go to definition" IDE feature. Consider using the routeRegistry approach 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 updating setInputProps to use callback style

For consistency with the createUpload changes and to fully support "Go to definition", consider updating the setInputProps call 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 implementation

The endpoint unwrapping mechanism is correctly implemented and used consistently.

Consider enhancing the deprecation notice to explain why routeConfig is preferred over permittedFileInfo:

    /**
-    * @deprecated Use `routeConfig` instead
+    * @deprecated Use `routeConfig` instead as it provides the same functionality with better type safety and IDE support
     */
    permittedFileInfo: routeConfig

Also 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 EndpointArg type for both useUploadThing and getRouteConfig functions.

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

📥 Commits

Files that changed from the base of the PR and between 70aa9fc and bf04779.

📒 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 the endpoint argument now additionall...

(NNS_THAT_VBZ)


[uncategorized] ~12-~12: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...he endpoint argument 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:

  1. Direct client usage with uploadFiles
  2. React hook usage with useUploadThing
  3. Component usage with UploadButton

The consistent pattern of using (routeRegistry) => routeRegistry.videoAndImage makes 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" support

The new endpoint implementation using routeRegistry enables IDE navigation to symbol definitions while maintaining type safety.

examples/with-clerk-pagesdir/src/pages/index.tsx (1)

30-30: ⚠️ Potential issue

Ensure consistent endpoint prop usage across components.

While the UploadDropzone component now uses the new function-based approach for better IDE support, the UploadButton component 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 expectTypeOf for 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-error annotations in unwrap.test.ts follows 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, and client-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 2

Length 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 uploadFiles and getRouteConfig in 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 uploadFiles and getRouteConfig use 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 videoAndImage symbol 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.videoAndImage is properly typed because:

  1. The routeRegistry object is created by genUploader internally (see packages/uploadthing/src/client.ts where createIdentityProxy is used)
  2. The type information flows through generateReactHelpers (from @uploadthing/react) which is used to create the components
  3. 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 the routeRegistry approach

The implementation correctly uses the function-based approach with routeRegistry, enabling the "Go to definition" IDE feature as intended.


53-53: Verify consistent usage of the videoAndImage endpoint

Let'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 videoAndImage endpoint across the codebase.

The videoAndImage endpoint usage is consistent across the codebase

The 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 2

Length of output: 10552

examples/backend-adapters/client-vanilla/src/resumable-upload.ts (1)

39-39: LGTM: Successfully implements "Go to definition" support

The 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 EndpointArg type 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 EndpointArg type in the codebase.

This will help us understand:

  1. All occurrences of EndpointArg in the codebase
  2. How it's defined and used in type definitions
  3. 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 uploadthing package 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 features

The 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 features

The addition of routeRegistry destructuring is key to enabling the "Go to definition" functionality, working in conjunction with the endpoint unwrapping mechanism.


53-56: LGTM: Type inference maintains safety

The 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 type

The 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 EndpointArg type.

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 EndpointArg with 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 EndpointArg type 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 EndpointArg import 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 of TEndpoint enables 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 EndpointArg type now supports three ways to specify the endpoint while maintaining type safety:

  1. String literal (original behavior)
  2. routeRegistry symbol (enables "Go to definition")
  3. 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 routeRegistry alongside uploadFiles enables the IDE navigation feature while maintaining existing functionality.

✅ Verification successful

Let me try a different approach to verify the genUploader implementation.

This will help us verify:

  1. The actual implementation of genUploader
  2. How it's exported and what it returns
  3. The type definition that should show if routeRegistry is part of the return type

From the results, I can see the genUploader implementation in packages/uploadthing/src/client.ts which shows that routeRegistry is indeed created using createIdentityProxy. 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 routeRegistry from genUploader is correct and type-safe

The implementation in packages/uploadthing/src/client.ts confirms that:

  • genUploader creates and returns routeRegistry using createIdentityProxy
  • RouteRegistry type is properly defined in packages/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 10

Length 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 5

Length of output: 994

packages/svelte/src/lib/create-uploadthing.ts (5)

7-7: LGTM: Import changes align with the PR objective.

The addition of unwrap and 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 routeRegistry from genUploader is 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 EndpointArg to 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 unwrap function implementation in packages/shared/src/utils.ts and its comprehensive test suite in packages/shared/test/unwrap.test.ts demonstrate 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) : x correctly 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 3

Length 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 EndpointArg type 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 TEndpoint to EndpointArg<TRouter, TEndpoint> successfully implements the three usage methods mentioned in the PR objectives:

  1. Type-safe string literal
  2. Imported routeRegistry
  3. 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 unwrap and EndpointArg aligns 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:

  1. Using EndpointArg type for the endpoint parameter
  2. Correctly resolving the endpoint using unwrap with the routeRegistry

Also applies to: 60-60, 136-137


157-160: LGTM: Proper initialization and exposure of client helpers.

The clientHelpers initialization is correctly placed to ensure the routeRegistry is 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:

  1. Type-safe string literal
  2. routeRegistry symbol
  3. 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 TEndpoint type
  • routeRegistry symbol through the RouteRegistry<TRouter> mapped type
  • Callback argument through the function type (_: RouteRegistry<TRouter>) => TEndpoint

The EndpointArg type 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 Json type import is appropriately added to support the new unwrap function'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.

Comment thread .changeset/twenty-rings-unite.md Resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

This branch was successfully deployed

1 active and 1 inactive (outdated) deployments
Preview – docs-uploadthing — b132bf97 Deployed Oct 23, 2024 by vercel[bot]
Preview – legacy-docs-uploadthing — f5044448 Deployed Oct 14, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants