-
-
Notifications
You must be signed in to change notification settings - Fork 699
Triggering docs and adding options to all trigger hooks #1528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: c603b7c The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 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 |
Caution Review failedThe pull request is closed. WalkthroughThe changes in this pull request enhance the Changes
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
packages/react-hooks/src/hooks/useTaskTrigger.tsOops! Something went wrong! :( ESLint: 8.45.0 ESLint couldn't find the config "custom" to extend from. Please check that the name of the config is correct. The config "custom" was referenced from the config file in "/.eslintrc.js". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (9)
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 (
|
There was a problem hiding this comment.
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 (13)
.changeset/nine-vans-perform.md (1)
1-5
: Enhance the changeset description with more details.While the patch version bump is appropriate for adding new options, the description could be more informative. Consider expanding it to include:
- List of trigger options that were added
- Impact on existing hook usage
- Any migration steps if needed
Example of a more detailed description:
--- "@trigger.dev/react-hooks": patch --- -Add trigger options to all trigger hooks +Add trigger options to all trigger hooks + +This patch introduces new configuration options for all trigger hooks in the package: +- List the key options added +- Mention any default values + +These options allow for more flexible hook configurations while maintaining backward compatibility. + +## Usage +Brief example of how to use the new optionsdocs/frontend/react-hooks/triggering.mdx (4)
68-69
: Enhance warning for multiple use tokensThe warning about multiple use tokens should be more prominent and explain the security implications.
- multipleUse: true, // ❌ Use this with caution! + multipleUse: true, // ⚠️ SECURITY RISK: Multiple use tokens can be reused by attackers if intercepted. Use only for development or when absolutely necessary.
97-99
: Enhance error handling exampleThe error handling could be more informative for users.
if (error) { - return <div>Error: {error.message}</div>; + return ( + <div role="alert" className="error-message"> + <h3>Error occurred while triggering task</h3> + <p>{error.message}</p> + {error.cause && <p>Cause: {error.cause.message}</p>} + </div> + ); }
177-178
: Add cleanup documentationAdd information about cleanup when the component unmounts.
Add the following note after the example:
<Note> The hook automatically handles cleanup of realtime subscriptions when the component unmounts. No manual cleanup is required. </Note>
217-220
: Enhance stream types documentationThe stream type example could be more comprehensive.
type STREAMS = { - openai: string; // this is the type of each "part" of the stream + openai: string; // Stream parts for OpenAI responses + progress: number; // Stream parts for progress updates + logs: { level: 'info' | 'error'; message: string }; // Stream parts for log messages };docs/frontend/react-hooks/overview.mdx (2)
7-7
: Fix grammatical issuesThere are two minor grammatical issues to address:
-Our react hooks package provides +Our React hooks package provides-If you are using Next.js with the App Router, you have to make sure the component that uses the `TriggerAuthContext` is a client component. So for example, the following code will not work: +If you are using Next.js with the App Router, you have to make sure the component that uses the `TriggerAuthContext` is a client component. So, for example, the following code will not work:Also applies to: 87-87
🧰 Tools
🪛 LanguageTool
[grammar] ~7-~7: “React” is a proper noun and needs to be capitalized.
Context: ...I from your React application. --- Our react hooks package provides a set of hooks t...(A_GOOGLE)
305-306
: Enhance polling interval guidanceThe polling warning could provide more specific guidance.
- Poll for updates at the specified interval (in milliseconds). Polling is not recommended for most - use-cases. Use the Realtime hooks instead. + Poll for updates at the specified interval (in milliseconds). Polling is not recommended due to API rate limits + and increased latency. For real-time updates, use the Realtime hooks which provide immediate updates via WebSocket + connections without polling overhead.docs/frontend/react-hooks/realtime.mdx (4)
91-91
: Fix grammatical error in the sentence.Add an apostrophe to make it possessive.
-To correctly type the runs payload and output, you can provide the type of your task to the `useRealtimeRunsWithTag` hook: +To correctly type the run's payload and output, you can provide the type of your task to the `useRealtimeRunsWithTag` hook:🧰 Tools
🪛 LanguageTool
[uncategorized] ~91-~91: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: .../div> ); } ``` To correctly type the runs payload and output, you can provide the...(AI_HYDRA_LEO_APOSTROPHE_S_XS)
205-205
: Fix grammatical error in the sentence.Use singular "type" with plural "streams".
-You can provide the type of the streams to the `useRealtimeRunWithStreams` hook: +You can provide the types of the streams to the `useRealtimeRunWithStreams` hook:🧰 Tools
🪛 LanguageTool
[grammar] ~205-~205: In this context, ‘type’ should agree in number with the noun after ‘of’.
Context: ... ); } ``` You can provide the type of the streams to theuseRealtimeRunWithStreams
hook...(TYPE_OF_PLURAL)
239-239
: Add missing comma in the sentence.Add a comma after "If instead of a pure text stream".
-As you can see above, each stream is an array of the type you provided, keyed by the stream name. If instead of a pure text stream you have a stream of objects, you can provide the type of the object: +As you can see above, each stream is an array of the type you provided, keyed by the stream name. If instead of a pure text stream, you have a stream of objects, you can provide the type of the object:🧰 Tools
🪛 LanguageTool
[uncategorized] ~239-~239: Possible missing comma found.
Context: ... stream name. If instead of a pure text stream you have a stream of objects, you can p...(AI_HYDRA_LEO_MISSING_COMMA)
34-34
: Add error type information in error handling examples.The error handling examples should include information about the possible error types to help developers handle specific error cases appropriately.
Add error type information in the examples:
- if (error) return <div>Error: {error.message}</div>; + if (error) { + // error is of type RealtimeError which can be: + // - ConnectionError: When the connection to the server fails + // - AuthenticationError: When the access token is invalid + // - SubscriptionError: When there's an error with the subscription + return <div>Error: {error.message}</div>; + }Also applies to: 57-57, 79-79, 156-156, 190-190, 226-226, 258-258
docs/triggering.mdx (2)
Line range hint
146-146
: Fix typo in the sentence.Remove the extra "the" in the sentence.
-The `useRealtimeBatch` hook allows you to subscribe to a batch of runs by its the batch ID. +The `useRealtimeBatch` hook allows you to subscribe to a batch of runs by its batch ID.🧰 Tools
🪛 LanguageTool
[style] ~701-~701: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...# Triggering from your frontend If you want to trigger a task directly from a frontend...(REP_WANT_TO_VB)
701-702
: Add missing information about frontend triggering.The section about triggering from frontend is incomplete. Consider adding a brief overview before redirecting to the React hooks documentation.
Add a brief overview:
## Triggering from your frontend +When triggering tasks from frontend applications, you need to consider: +- Authentication using Public Access Tokens +- Error handling and retry strategies +- Real-time updates and progress tracking + If you want to trigger a task directly from a frontend application, you can use our [React hooks](/frontend/react-hooks/triggering).🧰 Tools
🪛 LanguageTool
[style] ~701-~701: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...# Triggering from your frontend If you want to trigger a task directly from a frontend...(REP_WANT_TO_VB)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (9)
.changeset/nine-vans-perform.md
(1 hunks)docs/frontend/overview.mdx
(0 hunks)docs/frontend/react-hooks.mdx
(0 hunks)docs/frontend/react-hooks/overview.mdx
(1 hunks)docs/frontend/react-hooks/realtime.mdx
(1 hunks)docs/frontend/react-hooks/triggering.mdx
(1 hunks)docs/mint.json
(2 hunks)docs/triggering.mdx
(1 hunks)packages/react-hooks/src/hooks/useTaskTrigger.ts
(3 hunks)
💤 Files with no reviewable changes (2)
- docs/frontend/react-hooks.mdx
- docs/frontend/overview.mdx
🧰 Additional context used
🪛 LanguageTool
docs/frontend/react-hooks/overview.mdx
[grammar] ~7-~7: “React” is a proper noun and needs to be capitalized.
Context: ...I from your React application. --- Our react hooks package provides a set of hooks t...
(A_GOOGLE)
[uncategorized] ~87-~87: Possible missing comma found.
Context: ...ggerAuthContext` is a client component. So for example, the following code will no...
(AI_HYDRA_LEO_MISSING_COMMA)
docs/frontend/react-hooks/triggering.mdx
[uncategorized] ~115-~115: Loose punctuation mark.
Context: ...th the following properties: - submit
: A function that triggers the task. It t...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~116-~116: Loose punctuation mark.
Context: ...d of the task as an argument. - handle
: The run handle object. This object cont...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~117-~117: Loose punctuation mark.
Context: ...be used to access the run. - isLoading
: A boolean that indicates whether the ta...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~118-~118: Loose punctuation mark.
Context: ... is currently being triggered. - error
: An error object that contains any error...
(UNLIKELY_OPENING_PUNCTUATION)
docs/frontend/react-hooks/realtime.mdx
[uncategorized] ~91-~91: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: .../div> ); } ``` To correctly type the runs payload and output, you can provide the...
(AI_HYDRA_LEO_APOSTROPHE_S_XS)
[grammar] ~205-~205: In this context, ‘type’ should agree in number with the noun after ‘of’.
Context: ... ); } ``` You can provide the type of the streams to the useRealtimeRunWithStreams
hook...
(TYPE_OF_PLURAL)
[uncategorized] ~239-~239: Possible missing comma found.
Context: ... stream name. If instead of a pure text stream you have a stream of objects, you can p...
(AI_HYDRA_LEO_MISSING_COMMA)
🔇 Additional comments (6)
packages/react-hooks/src/hooks/useTaskTrigger.ts (3)
11-11
: LGTM: Clean import addition
The TriggerOptions type import is correctly added and necessary for the interface changes.
Line range hint 65-84
: LGTM: Comprehensive options handling
The implementation thoroughly processes all trigger options with proper type safety. The idempotencyKey is correctly handled using makeIdempotencyKey, and all option fields are properly passed to the apiClient.
121-121
: LGTM: Consistent interface updates
The addition of optional TriggerOptions is consistent across all interfaces and maintains backward compatibility.
Let's verify that all consumers of these interfaces are updated correctly:
Also applies to: 169-169
docs/mint.json (1)
113-116
: LGTM: Documentation structure changes
The changes to redirects and navigation structure are well-organized and maintain consistency with the new documentation layout.
Also applies to: 214-221
docs/frontend/react-hooks/realtime.mdx (1)
1-391
: Documentation structure and examples are well organized.
The documentation provides clear explanations, proper TypeScript examples, and covers important aspects like error handling, type safety, and configuration options.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~91-~91: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: .../div> ); } ``` To correctly type the runs payload and output, you can provide the...
(AI_HYDRA_LEO_APOSTROPHE_S_XS)
[grammar] ~205-~205: In this context, ‘type’ should agree in number with the noun after ‘of’.
Context: ... ); } ``` You can provide the type of the streams to the useRealtimeRunWithStreams
hook...
(TYPE_OF_PLURAL)
[uncategorized] ~239-~239: Possible missing comma found.
Context: ... stream name. If instead of a pure text stream you have a stream of objects, you can p...
(AI_HYDRA_LEO_MISSING_COMMA)
docs/triggering.mdx (1)
Line range hint 1-1000
: Documentation is comprehensive and well-structured.
The documentation provides thorough coverage of task triggering, including:
- Clear explanations of different triggering methods
- Proper code examples with TypeScript
- Important warnings and notes about potential pitfalls
- Comprehensive coverage of options and configurations
🧰 Tools
🪛 LanguageTool
[style] ~701-~701: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...# Triggering from your frontend If you want to trigger a task directly from a frontend...
(REP_WANT_TO_VB)
``` | ||
|
||
```bash yarn | ||
yarn install @trigger.dev/react-hooks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix yarn installation command
The yarn installation command is incorrect and would fail.
-yarn install @trigger.dev/react-hooks
+yarn add @trigger.dev/react-hooks
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
yarn install @trigger.dev/react-hooks | |
yarn add @trigger.dev/react-hooks |
@trigger.dev/react-hooks
@trigger.dev/rsc
@trigger.dev/build
trigger.dev
@trigger.dev/sdk
@trigger.dev/core
commit: |
b4ce9fa
to
c603b7c
Compare
Summary by CodeRabbit
New Features
@trigger.dev/react-hooks
, detailing usage and integration.useTaskTrigger
,useRealtimeTaskTrigger
, anduseRealtimeTaskTriggerWithStreams
.Documentation
Bug Fixes