Skip to content

feat: create prefetch functions for Tanstack Query plugin #1715

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

Closed
wants to merge 5 commits into from
Closed

feat: create prefetch functions for Tanstack Query plugin #1715

wants to merge 5 commits into from

Conversation

Arkanii
Copy link
Contributor

@Arkanii Arkanii commented Sep 18, 2024

Hello!

I need help with this one. 😓
I'm trying to run this on Svelte but prefetch queries need to be executed on the server so I can't use the getHooksContext function and I can't find any solution for it yet.

I also need to test on Vue and React. If anyone can test it that would be great as I don't have much time to test on all three frameworks. 🙏🏻

Thanks !

Svelte error: lifecycle_outside_component
2024-09-18T16:10:51.139896568Z `getContext(...)` can only be used during component initialisation
2024-09-18T16:10:51.139903231Z     at Module.lifecycle_outside_component (/srv/app/node_modules/svelte/src/internal/shared/errors.js:28:17)
2024-09-18T16:10:51.139909643Z     at get_or_init_context_map (/srv/app/node_modules/svelte/src/internal/server/context.js:51:5)
2024-09-18T16:10:51.139915794Z     at Module.getContext (/srv/app/node_modules/svelte/src/internal/server/context.js:15:22)
2024-09-18T16:10:51.139921936Z     at Module.getHooksContext (/srv/app/node_modules/@zenstackhq/src/runtime-v5/svelte.ts:48:35)
2024-09-18T16:10:51.139963213Z     at Module.usePrefetchFindManyTodo (/srv/app/src/lib/hooks/todo.ts:65:33)
2024-09-18T16:10:51.139967551Z     at load (/srv/app/src/routes/(website)/(home)/+page.ts:7:8)
2024-09-18T16:10:51.139971478Z     at async Module.load_data (/srv/app/node_modules/@sveltejs/kit/src/runtime/server/page/load_data.js:192:17)
2024-09-18T16:10:51.139975546Z     at async eval (/srv/app/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:168:13)

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant enhancements to the tanstack-query plugin, particularly focusing on prefetching capabilities. Key changes include the addition of a generatePrefetch option in various functions, updates to function signatures, and the introduction of new functions for prefetching and fetching queries across different frameworks (React, Vue, Svelte). The test suite has also been updated to validate these new functionalities, ensuring that the plugin can effectively handle prefetching operations.

Changes

File Path Change Summary
packages/plugins/tanstack-query/src/generator.ts - Added generatePrefetch option to various functions.
- Updated generate, generateQueryHook, and makeQueryArgsType function signatures.
- Introduced makePrefetchQueryOptions function.
packages/plugins/tanstack-query/src/runtime-v5/vue.ts - Added new types and functions for query handling.
- Defined MaybeRefDeep type.
- Introduced prefetchModelQuery, fetchModelQuery, prefetchInfiniteModelQuery, and fetchInfiniteModelQuery functions.
packages/plugins/tanstack-query/src/runtime/index.ts - Added DEFAULT_QUERY_ENDPOINT and ExtraPrefetchOptions exports.
packages/plugins/tanstack-query/src/runtime/common.ts - Introduced ExtraPrefetchOptions type for prefetching options.
packages/plugins/tanstack-query/tests/plugin.test.ts - Updated test suite to validate prefetch functionality across frameworks.
- Added makePrefetchSource function for generating prefetch source objects.

Possibly related PRs


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

@ymc9
Copy link
Member

ymc9 commented Sep 20, 2024

Hey @Arkanii , thanks for making this PR. I'll follow up here a bit later.

@ymc9
Copy link
Member

ymc9 commented Sep 30, 2024

Hello!

I need help with this one. 😓 I'm trying to run this on Svelte but prefetch queries need to be executed on the server so I can't use the getHooksContext function and I can't find any solution for it yet.

I also need to test on Vue and React. If anyone can test it that would be great as I don't have much time to test on all three frameworks. 🙏🏻

Thanks !

Svelte error: lifecycle_outside_component
2024-09-18T16:10:51.139896568Z `getContext(...)` can only be used during component initialisation
2024-09-18T16:10:51.139903231Z     at Module.lifecycle_outside_component (/srv/app/node_modules/svelte/src/internal/shared/errors.js:28:17)
2024-09-18T16:10:51.139909643Z     at get_or_init_context_map (/srv/app/node_modules/svelte/src/internal/server/context.js:51:5)
2024-09-18T16:10:51.139915794Z     at Module.getContext (/srv/app/node_modules/svelte/src/internal/server/context.js:15:22)
2024-09-18T16:10:51.139921936Z     at Module.getHooksContext (/srv/app/node_modules/@zenstackhq/src/runtime-v5/svelte.ts:48:35)
2024-09-18T16:10:51.139963213Z     at Module.usePrefetchFindManyTodo (/srv/app/src/lib/hooks/todo.ts:65:33)
2024-09-18T16:10:51.139967551Z     at load (/srv/app/src/routes/(website)/(home)/+page.ts:7:8)
2024-09-18T16:10:51.139971478Z     at async Module.load_data (/srv/app/node_modules/@sveltejs/kit/src/runtime/server/page/load_data.js:192:17)
2024-09-18T16:10:51.139975546Z     at async eval (/srv/app/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:168:13)

Hi @Arkanii , my apologies for the late response. Just to clarify your goal here. Do you want to do server-side prefetch with SvelteKit? If so, maybe we should simply generate a set of presetFindManyModel etc. async functions (that wraps queryClient.prefetchQuery inside), instead of generating usePrefetchQuery?

@Arkanii
Copy link
Contributor Author

Arkanii commented Oct 2, 2024

Hello!
I need help with this one. 😓 I'm trying to run this on Svelte but prefetch queries need to be executed on the server so I can't use the getHooksContext function and I can't find any solution for it yet.
I also need to test on Vue and React. If anyone can test it that would be great as I don't have much time to test on all three frameworks. 🙏🏻
Thanks !

Svelte error: lifecycle_outside_component
2024-09-18T16:10:51.139896568Z `getContext(...)` can only be used during component initialisation
2024-09-18T16:10:51.139903231Z     at Module.lifecycle_outside_component (/srv/app/node_modules/svelte/src/internal/shared/errors.js:28:17)
2024-09-18T16:10:51.139909643Z     at get_or_init_context_map (/srv/app/node_modules/svelte/src/internal/server/context.js:51:5)
2024-09-18T16:10:51.139915794Z     at Module.getContext (/srv/app/node_modules/svelte/src/internal/server/context.js:15:22)
2024-09-18T16:10:51.139921936Z     at Module.getHooksContext (/srv/app/node_modules/@zenstackhq/src/runtime-v5/svelte.ts:48:35)
2024-09-18T16:10:51.139963213Z     at Module.usePrefetchFindManyTodo (/srv/app/src/lib/hooks/todo.ts:65:33)
2024-09-18T16:10:51.139967551Z     at load (/srv/app/src/routes/(website)/(home)/+page.ts:7:8)
2024-09-18T16:10:51.139971478Z     at async Module.load_data (/srv/app/node_modules/@sveltejs/kit/src/runtime/server/page/load_data.js:192:17)
2024-09-18T16:10:51.139975546Z     at async eval (/srv/app/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:168:13)

Hi @Arkanii , my apologies for the late response. Just to clarify your goal here. Do you want to do server-side prefetch with SvelteKit? If so, maybe we should simply generate a set of presetFindManyModel etc. async functions (that wraps queryClient.prefetchQuery inside), instead of generating usePrefetchQuery?

Hello ! No problem. 😄
Yes, my goal here is to do server-side prefetch with SvelteKit to reduce loading times, and to do it for other frameworks too if it can helps someone.

I'll try to check your idea a lit later.
If you or someone else want to edit my PR, no problem !

@Arkanii
Copy link
Contributor Author

Arkanii commented Oct 11, 2024

Mmmh I think it's too complicated for me to end this...
Do you have any tip for me ? thanks

@ymc9
Copy link
Member

ymc9 commented Oct 11, 2024

Mmmh I think it's too complicated for me to end this... Do you have any tip for me ? thanks

No worries @Arkanii , I'll follow up on this PR!

@ymc9 ymc9 marked this pull request as ready for review October 16, 2024 04:24
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 10

🧹 Outside diff range and nitpick comments (3)
packages/plugins/tanstack-query/src/runtime-v5/svelte.ts (1)

119-120: Clarify optimisticUpdate Logic

In constructing the queryKey, the optimisticUpdate property is set using:

optimisticUpdate: options?.optimisticUpdate !== false,

This logic means that optimisticUpdate defaults to true unless explicitly set to false. While functional, this can be confusing.

Consider simplifying the logic for clarity:

- optimisticUpdate: options?.optimisticUpdate !== false,
+ optimisticUpdate: options?.optimisticUpdate ?? true,

This change makes it clear that if optimisticUpdate is undefined, it defaults to true.

packages/plugins/tanstack-query/tests/plugin.test.ts (1)

229-229: Avoid using latest in dependency versions

In the extraDependencies, you have specified @tanstack/vue-query@latest. Using latest can lead to unpredictable builds if the package is updated. Consider pinning to a specific version to ensure consistent and reliable builds.

packages/plugins/tanstack-query/src/generator.ts (1)

28-29: Consider Refactoring into a Class for Better Parameter Management

The TODO comment suggests turning the code into a class to simplify parameter passing. Refactoring into a class can enhance code organization, maintainability, and readability by encapsulating related functionalities and reducing the need for passing multiple parameters through functions.

Would you like assistance in refactoring this code into a class structure?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d83b7ee and 44567cc.

📒 Files selected for processing (5)
  • packages/plugins/tanstack-query/src/generator.ts (17 hunks)
  • packages/plugins/tanstack-query/src/runtime-v5/react.ts (3 hunks)
  • packages/plugins/tanstack-query/src/runtime-v5/svelte.ts (5 hunks)
  • packages/plugins/tanstack-query/src/runtime-v5/vue.ts (5 hunks)
  • packages/plugins/tanstack-query/tests/plugin.test.ts (7 hunks)
🧰 Additional context used
🪛 Biome
packages/plugins/tanstack-query/src/runtime-v5/vue.ts

[error] 40-40: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

🔇 Additional comments (18)
packages/plugins/tanstack-query/src/runtime-v5/svelte.ts (3)

110-128: Avoid Unnecessary Type Assertions in prefetchModelQuery

In the prefetchModelQuery function, when calling queryClient.prefetchQuery, you're spreading ...options without the need for a type assertion. This is good practice. However, please ensure that the types of options align correctly with the expected parameters to maintain type safety and avoid potential runtime errors.


Line range hint 282-298: Verify getContext Usage for SSR Compatibility

The useModelMutation function uses getContext to access the logging configuration:

const { logging } = getContext<APIContext>(SvelteQueryContextKey);

Since getContext is a Svelte function that may not be available during server-side rendering (SSR), this could cause issues when performing mutations on the server.

Run the following script to check for getContext usage and assess its compatibility with SSR:

#!/bin/bash
# Description: Find all usages of getContext in mutation functions

rg --type typescript 'getContext<APIContext>'

Ensure that getContext is not called during SSR or provide alternative methods for accessing context data when on the server. Consider injecting the necessary context or using a different approach that is SSR-safe.


111-117: Ensure Safe Handling of Optional fetch Parameter

In the prefetchModelQuery function, the fetch parameter is optional. Verify that the fetcher function can handle an undefined fetch parameter without causing errors.

Run the following script to check where fetcher is used and ensure it handles undefined safely:

Ensure that all code paths in fetcher account for fetch being undefined and provide appropriate fallbacks or error handling.

packages/plugins/tanstack-query/tests/plugin.test.ts (7)

79-104: Well-structured function to generate prefetch source files

The makePrefetchSource function is properly implemented to create prefetch source files for different targets, enhancing the plugin's capabilities.


135-135: Enabling prefetch generation in React plugin configuration

Setting generatePrefetch = true in the plugin configuration correctly enables the prefetch functions for React v5.


162-162: Verify the inclusion of suspense.ts in Vue and Svelte tests

The suspense.ts source file is included in the React plugin tests to cover Suspense features but is not included in the Vue and Svelte plugin tests. If Suspense is also supported in Vue and Svelte, consider adding similar test cases for consistency.


226-226: Enabling prefetch generation in Vue plugin configuration

Setting generatePrefetch = true in the plugin configuration correctly enables the prefetch functions for Vue v5.


237-237: Including prefetch source files in Vue tests

Adding makePrefetchSource('vue') to extraSourceFiles correctly includes the prefetch source files in the Vue tests.


301-301: Enabling prefetch generation in Svelte plugin configuration

Setting generatePrefetch = true in the plugin configuration correctly enables the prefetch functions for Svelte v5.


312-312: Including prefetch source files in Svelte tests

Adding makePrefetchSource('svelte') to extraSourceFiles correctly includes the prefetch source files in the Svelte tests.

packages/plugins/tanstack-query/src/runtime-v5/react.ts (1)

Line range hint 84-250: Verify consistency across different frameworks

Given the PR's objective to implement prefetch functions across React, Vue, and Svelte, ensure that similar functions are implemented in the corresponding files for Vue and Svelte. This maintains feature parity across all supported frameworks.

To check for the existence of similar implementations in Vue and Svelte, you can run:

✅ Verification successful

Consistency across different frameworks verified successfully.

All prefetch functions are implemented in Vue and Svelte runtime files, ensuring feature parity across React, Vue, and Svelte.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that prefetch functions are implemented in Vue and Svelte runtime files.

# Search for 'prefetchModelQuery' in Vue files
fd --type f 'vue.ts' | xargs rg 'export function prefetchModelQuery'

# Search for 'prefetchModelQuery' in Svelte files
fd --type f 'svelte.ts' | xargs rg 'export function prefetchModelQuery'

Length of output: 381

packages/plugins/tanstack-query/src/runtime-v5/vue.ts (5)

8-11: Addition of necessary imports for query handling

The imports of FetchInfiniteQueryOptions, FetchQueryOptions, and QueryClient from @tanstack/vue-query are appropriate and required for the new functions.


107-137: New function prefetchModelQuery enhances prefetching capabilities

The prefetchModelQuery function is correctly implemented, allowing prefetching of queries using the QueryClient. This addition adheres to best practices and improves the library's functionality.


149-169: New function fetchModelQuery for fetching queries

The fetchModelQuery function is appropriately implemented, enabling fetching of queries with the QueryClient. The implementation is correct and aligns with the expected usage.


219-240: New function prefetchInfiniteModelQuery for infinite queries

The prefetchInfiniteModelQuery function effectively adds prefetching capabilities for infinite queries. The implementation is correct and follows best practices.


252-273: New function fetchInfiniteModelQuery added for infinite queries

The fetchInfiniteModelQuery function is correctly implemented, allowing fetching of infinite queries using the QueryClient. This enhances the library's functionality for handling infinite queries.

packages/plugins/tanstack-query/src/generator.ts (2)

45-55: LGTM: Error Handling Logic is Correct

The added error handling correctly validates the generatePrefetch option's type and ensures compatibility with version 'v4'. This enhances the robustness of the code by providing clear error messages to the user.


183-234: Ensure Server-Side Compatibility in Prefetch Functions

The addition of prefetch functions enhances functionality, but ensure that they are compatible with server-side execution across all supported frameworks. Particular attention is needed for Svelte, where certain client-side APIs may not be available server-side.

Consider reviewing the implementation to ensure that all server-side requirements are met and that framework-specific nuances are handled appropriately.

You can use the following script to identify potential client-side API usage in prefetch functions:

#!/bin/bash
# Description: Search for client-side APIs used in prefetch functions that may not be server-compatible.

# Expected: Prefetch functions should not use client-side only APIs like getHooksContext.
rg --type ts "getHooksContext|getContext" -A 5

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (7)
packages/plugins/tanstack-query/src/runtime/index.ts (2)

Line range hint 1-9: LGTM! Consider adding documentation for new exports.

The additions of DEFAULT_QUERY_ENDPOINT and ExtraPrefetchOptions align well with the PR objectives of implementing server-side prefetching. These new exports will likely enhance the plugin's prefetching capabilities.

Consider adding inline documentation (JSDoc comments) for the new exports to explain their purpose and usage, especially for ExtraPrefetchOptions. This would help developers understand how to use these new features in the context of server-side prefetching.


Line range hint 1-9: Summary: Good progress on server-side prefetching implementation

The changes in this file are a step in the right direction for implementing server-side prefetching. The addition of DEFAULT_QUERY_ENDPOINT and ExtraPrefetchOptions provides the necessary building blocks for this functionality.

Regarding the challenges mentioned in the PR objectives:

  1. For the Svelte-specific issue with getContext(...), this file doesn't directly address it. You might need to look into creating a Svelte-specific implementation that doesn't rely on getContext for server-side operations.

  2. For testing across Vue and React frameworks, these changes should be framework-agnostic, which is good. However, you'll need to ensure that the implementation of these new exports in the ./common file works correctly across all frameworks.

Consider creating separate files for framework-specific implementations (e.g., svelte.ts, react.ts, vue.ts) that utilize these common exports. This could help address the Svelte-specific issues while maintaining a consistent API across frameworks.

Would you like assistance in creating these framework-specific files or in implementing the server-side prefetching logic using these new exports?

packages/plugins/tanstack-query/src/runtime/common.ts (1)

113-116: LGTM! Consider adding a brief comment.

The new ExtraPrefetchOptions type is a good addition, aligning well with the PR's objective of implementing server-side prefetching. It's correctly defined as a subset of APIContext, focusing on the essential properties for prefetching.

Consider adding a brief comment explaining the purpose of this type, similar to the comments for other type definitions in this file. For example:

/**
 * Extra options for prefetching queries.
 */
export type ExtraPrefetchOptions = Pick<APIContext, 'endpoint' | 'fetch'>;
packages/plugins/tanstack-query/src/generator.ts (2)

Line range hint 87-234: LGTM with suggestion: Consider refactoring for improved readability

The changes to generateQueryHook correctly implement the new functionality for prefetching and nullable types. However, the function has grown quite large and complex.

Consider refactoring this function into smaller, more focused functions to improve readability and maintainability. For example, you could extract the prefetch hook generation into a separate function.

Here's a suggestion for refactoring:

function generatePrefetchHooks(sf: SourceFile, model: string, operation: string, capOperation: string, argsType: string, inputType: string, returnType: string, supportInfinite: boolean, overrideTypeParameters?: string[]) {
    const modes = [
        { mode: 'prefetch', infinite: false },
        { mode: 'fetch', infinite: false },
    ];
    if (supportInfinite) {
        modes.push({ mode: 'prefetch', infinite: true }, { mode: 'fetch', infinite: true });
    }

    for (const { mode, infinite } of modes) {
        // ... (rest of the prefetch hook generation logic)
    }
}

function generateQueryHook(
    // ... (existing parameters)
) {
    // ... (existing logic for non-prefetch hooks)

    if (generatePrefetch) {
        generatePrefetchHooks(sf, model, operation, capOperation, argsType, inputType, returnType, supportInfinite, overrideTypeParameters);
    }
}

This refactoring would make the generateQueryHook function more manageable and easier to understand.


Line range hint 768-779: LGTM with suggestion: Consider adding explicit return type

The changes to makeQueryArgsType correctly handle the different requirements for prefetch and non-prefetch scenarios in Vue. This is a good improvement for type safety.

To further enhance clarity and type safety, consider adding an explicit return type to the function:

function makeQueryArgsType(target: string, argsType: string, prefetch: boolean): string {
    // ... (existing implementation)
}

This will make the function's contract clearer and help catch any potential type-related issues earlier.

packages/plugins/tanstack-query/src/runtime-v5/vue.ts (2)

Line range hint 188-198: Investigate and resolve typing issues in useInfiniteModelQuery

The usage of any for queryOptions suggests there are typing issues with vue-query's useInfiniteQuery. This reduces type safety and may mask potential errors. Consider reviewing the typings or updating the dependencies to address this issue.

I can help investigate the typing issues with useInfiniteQuery to find a solution that maintains type safety without resorting to any.


Line range hint 282-298: Resolve the typing issue to eliminate any in useModelMutation

The use of any for finalOptions due to typing problems reduces type safety. Addressing the typing issues will improve code reliability and maintain the benefits of TypeScript's type checking.

I noticed the TODO comment about the typing problem. Would you like assistance in refining the types to eliminate the use of any?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 44567cc and c374642.

📒 Files selected for processing (5)
  • packages/plugins/tanstack-query/src/generator.ts (16 hunks)
  • packages/plugins/tanstack-query/src/runtime-v5/index.ts (1 hunks)
  • packages/plugins/tanstack-query/src/runtime-v5/vue.ts (5 hunks)
  • packages/plugins/tanstack-query/src/runtime/common.ts (1 hunks)
  • packages/plugins/tanstack-query/src/runtime/index.ts (1 hunks)
🧰 Additional context used
🪛 Biome
packages/plugins/tanstack-query/src/runtime-v5/vue.ts

[error] 40-40: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

🔇 Additional comments (6)
packages/plugins/tanstack-query/src/runtime-v5/index.ts (1)

Line range hint 1-9: LGTM! New exports align with PR objectives.

The addition of DEFAULT_QUERY_ENDPOINT and ExtraPrefetchOptions to the exports is consistent with the PR's goal of implementing server-side prefetching for queries. These new exports will likely be used in the prefetching implementation across different frameworks.

To ensure the correct implementation of these new exports, please run the following script:

This will help confirm that these exports are properly defined in the common runtime file.

✅ Verification successful

LGTM! Verified the implementation of new exports.

The definitions for DEFAULT_QUERY_ENDPOINT and ExtraPrefetchOptions are correctly implemented in common.ts, aligning with the PR's objectives for server-side prefetching.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of new exports in the common runtime file

# Test: Check the implementation of DEFAULT_QUERY_ENDPOINT and ExtraPrefetchOptions
rg --type typescript -A 5 'DEFAULT_QUERY_ENDPOINT|ExtraPrefetchOptions' packages/plugins/tanstack-query/src/runtime/common.ts

Length of output: 162


Script:

#!/bin/bash
# Description: Verify the definitions of DEFAULT_QUERY_ENDPOINT and ExtraPrefetchOptions in the common runtime file

# Check for DEFAULT_QUERY_ENDPOINT definition
rg 'export\s+const\s+DEFAULT_QUERY_ENDPOINT' packages/plugins/tanstack-query/src/runtime/common.ts

# Check for ExtraPrefetchOptions type definition
rg 'export\s+type\s+ExtraPrefetchOptions' packages/plugins/tanstack-query/src/runtime/common.ts

Length of output: 325

packages/plugins/tanstack-query/src/runtime/common.ts (2)

Line range hint 1-478: Overall assessment: LGTM

The addition of the ExtraPrefetchOptions type is a minimal and non-disruptive change that aligns well with the PR's objective of implementing server-side prefetching. It follows the existing coding style and naming conventions in the file.

To fully validate this change:

  1. Ensure that the ExtraPrefetchOptions type is used effectively in the implementation of prefetching functionality in other files.
  2. Confirm that the prefetching implementation addresses the challenges mentioned in the PR objectives, particularly regarding the use of getHooksContext and the Svelte-specific issues.

113-116: Verify usage of ExtraPrefetchOptions in other files.

The new ExtraPrefetchOptions type is well-defined and exported, but it's not used within this file. To ensure its effectiveness and necessity:

  1. Confirm that this type is used in the implementation of prefetching functionality in other files.
  2. Verify that the selected properties (endpoint and fetch) are sufficient for the prefetching requirements.

To check the usage of ExtraPrefetchOptions across the codebase, run the following script:

✅ Verification successful

ExtraPrefetchOptions is properly utilized across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage of ExtraPrefetchOptions in other files

# Search for imports of ExtraPrefetchOptions
echo "Files importing ExtraPrefetchOptions:"
rg "import.*ExtraPrefetchOptions" --type ts

# Search for usage of ExtraPrefetchOptions
echo "\nUsage of ExtraPrefetchOptions:"
rg "ExtraPrefetchOptions" --type ts

Length of output: 895

packages/plugins/tanstack-query/src/generator.ts (3)

45-54: LGTM: Proper handling of the new generatePrefetch option

The changes correctly validate the generatePrefetch option and ensure it's only used with version "v5". This is a good addition to maintain compatibility and prevent misuse.


828-838: LGTM: Well-implemented makePrefetchQueryOptions function

The new makePrefetchQueryOptions function is a good addition. It correctly handles both infinite and non-infinite queries, and includes the appropriate extra options. The function is concise and easy to understand.


421-422: LGTM: Consistent implementation of prefetch functionality

The minor changes throughout the file, including updates to various functions to include the generatePrefetch parameter and the addition of new import statements, are consistent with the overall addition of prefetch functionality. These changes appear to be correctly implemented and maintain the coherence of the codebase.

Also applies to: 429-429, 709-725, 747-748

@ymc9
Copy link
Member

ymc9 commented Oct 16, 2024

Hi @Arkanii , I've made some progress to change the PR to generate prefetch[Action][Model] and fetch[Action][Model] instead, which is probably more versatile than usePrefetch.

However, I believe more though and work is needed about how data is actually fetched from the server side. It's complicated and not performant if the hooks still send an HTTP request. It should probably just directly call enhanced prisma client.

May I keep the PR open for now and continue thinking about this? I really appreciate that you started this effort. It's been a long-waited feature!

@Arkanii
Copy link
Contributor Author

Arkanii commented Oct 17, 2024

Hi @Arkanii , I've made some progress to change the PR to generate prefetch[Action][Model] and fetch[Action][Model] instead, which is probably more versatile than usePrefetch.

However, I believe more though and work is needed about how data is actually fetched from the server side. It's complicated and not performant if the hooks still send an HTTP request. It should probably just directly call enhanced prisma client.

May I keep the PR open for now and continue thinking about this? I really appreciate that you started this effort. It's been a long-waited feature!

Sure no problem ! I'll just put it in draft.
Thanks to you to accept to work my PR. 🙏🏻

@Arkanii Arkanii marked this pull request as draft October 17, 2024 13:08
@Arkanii Arkanii closed this by deleting the head repository Oct 25, 2024
@Arkanii
Copy link
Contributor Author

Arkanii commented Nov 5, 2024

ops sorry @ymc9 I closed the PR...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants