Skip to content
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

Biz/dj 2786 fix issue with loading dynamic props #15142

Closed

Conversation

bzwrk
Copy link
Contributor

@bzwrk bzwrk commented Jan 2, 2025

WHY

Dynamic props aren't loading (this only happens if we need to reload props more than once, eg. Google sheets, where we fetch dynamicProps for the first time after selecting the sheet. But we also need to fetch the dynamic props after selecting a worksheet, and so on.) The root cause appears to be useQuery, which only executes queryFn once for a given queryKey. Ideally, useQuery should run once for a given reloadPropIdx. So far the only thing that works is invalidating the queryKey.

Summary by CodeRabbit

  • Version Update

    • Updated @pipedream/connect-react package version from 1.0.0-preview.15 to 1.0.0-preview.16
  • Improvements

    • Enhanced query key handling in form context hook to improve dynamic property management

Copy link

linear bot commented Jan 2, 2025

Copy link

vercel bot commented Jan 2, 2025

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

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Jan 4, 2025 1:00am
pipedream-docs ⬜️ Ignored (Inspect) Jan 4, 2025 1:00am
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jan 4, 2025 1:00am

Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

This pull request involves two primary changes: updating the version of the @pipedream/connect-react package from 1.0.0-preview.15 to 1.0.0-preview.16, and modifying the useFormContext hook in form-context.tsx to dynamically construct a query key based on a new variable, queryKeyInput. The changes enhance the flexibility of query key generation while maintaining the overall structure of the component.

Changes

File Change Summary
packages/connect-react/package.json Version bumped from 1.0.0-preview.15 to 1.0.0-preview.16
packages/connect-react/src/hooks/form-context.tsx Added dynamic queryKey construction using queryKeyInput in useFormContext hook

Possibly related PRs

  • Fix dynamic props in the Connect demo app #14887: This PR modifies the form-context.tsx file, which is directly related to the changes made in the main PR regarding the useFormContext hook and the FormContextProvider component.
  • Je/connect react triggers #14985: This PR introduces changes to the form-context.tsx file, adding a new constant skippablePropTypes, which relates to the modifications made in the main PR concerning the dynamic handling of the query key in the useQuery hook.
  • Review and update prop validation logic for accuracy #14986: This PR updates the form-context.tsx file by adding an errors property to the FormContext type, which is relevant to the changes in the main PR that enhance the flexibility of the useFormContext hook.

Suggested labels

bug, dependencies, tracked internally

Suggested reviewers

  • adolfo-pd
  • tjk

Poem

🐰 A rabbit's tale of code so bright,
Version bumped with query key's might,
Dynamic paths now clearly seen,
Flexibility reigns supreme!
Hop, hop, hooray for clean design! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3219de and 3d7a920.

📒 Files selected for processing (1)
  • packages/connect-react/src/hooks/form-context.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/connect-react/src/hooks/form-context.tsx

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@bzwrk bzwrk requested a review from tjk January 2, 2025 23:35
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: 1

🧹 Nitpick comments (1)
packages/connect-react/src/hooks/form-context.tsx (1)

138-138: Add a trailing comma to the array for compliance with the style rules

This line triggers a lint error about the missing trailing comma. Update the array as follows:

-    queryKey: [
-      queryKey
-    ],
+    queryKey: [
+      queryKey,
+    ],
🧰 Tools
🪛 eslint

[error] 138-139139: Missing trailing comma.

(comma-dangle)

🪛 GitHub Check: Lint Code Base

[failure] 138-138138:
Missing trailing comma

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3faa18 and d6a99e7.

📒 Files selected for processing (2)
  • packages/connect-react/package.json (1 hunks)
  • packages/connect-react/src/hooks/form-context.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/connect-react/package.json
🧰 Additional context used
🪛 eslint
packages/connect-react/src/hooks/form-context.tsx

[error] 132-132132: Expected newline between test and consequent of ternary expression.

(multiline-ternary)


[error] 132-132132: Expected newline between consequent and alternate of ternary expression.

(multiline-ternary)

🪛 GitHub Check: Lint Code Base
packages/connect-react/src/hooks/form-context.tsx

[failure] 132-132132:
Expected newline between test and consequent of ternary expression


[failure] 132-132132:
Expected newline between consequent and alternate of ternary expression


[failure] 138-138138:
Missing trailing comma

🪛 GitHub Actions: Pull Request Checks
packages/connect-react/src/hooks/form-context.tsx

[error] 132-132132: Expected newline between test and consequent of ternary expression (multiline-ternary)

@@ -129,12 +129,13 @@
configuredProps,
dynamicPropsId: dynamicProps?.id,
};
const queryKey = reloadPropIdx ? `dynamicProps:${reloadPropIdx}` : "dynamicProps"
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor the ternary expression to satisfy lint requirements

Currently, the linter complains about the multiline ternary usage on this line. Splitting the condition, the true branch, and false branch across separate lines will fix the issue:

-const queryKey = reloadPropIdx ? `dynamicProps:${reloadPropIdx}` : "dynamicProps"
+const queryKey = reloadPropIdx
+  ? `dynamicProps:${reloadPropIdx}`
+  : "dynamicProps";
📝 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.

Suggested change
const queryKey = reloadPropIdx ? `dynamicProps:${reloadPropIdx}` : "dynamicProps"
const queryKey = reloadPropIdx
? `dynamicProps:${reloadPropIdx}`
: "dynamicProps";
🧰 Tools
🪛 eslint

[error] 132-132132: Expected newline between test and consequent of ternary expression.

(multiline-ternary)


[error] 132-132132: Expected newline between consequent and alternate of ternary expression.

(multiline-ternary)

🪛 GitHub Check: Lint Code Base

[failure] 132-132132:
Expected newline between test and consequent of ternary expression


[failure] 132-132132:
Expected newline between consequent and alternate of ternary expression

🪛 GitHub Actions: Pull Request Checks

[error] 132-132132: Expected newline between test and consequent of ternary expression (multiline-ternary)

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

🔭 Outside diff range comments (2)
packages/connect-react/src/hooks/form-context.tsx (2)

Line range hint 141-155: Consider enhancing the query's enabled condition.

The current implementation enables the query only when reloadPropIdx != null. However, based on the PR objectives, we might want to consider additional conditions to handle edge cases:

  1. Initial load of dynamic props
  2. Forced reloads
  3. Recovery from errors
    enabled: reloadPropIdx != null, // TODO or props.dynamicPropsId && !dynamicProps
+    enabled: Boolean(
+      // Enable on explicit reload request
+      reloadPropIdx != null ||
+      // Enable on initial load when we have a dynamic props ID but no data
+      (formProps.dynamicPropsId && !dynamicProps) ||
+      // Enable when configured props change and we need to reload
+      (dynamicProps?.id && Object.keys(configuredProps).length > 0)
+    ),

This enhancement would better handle the Google Sheets scenario mentioned in the PR description, where dynamic properties need to be fetched multiple times.

🧰 Tools
🪛 eslint

[error] 142-143: Missing trailing comma.

(comma-dangle)

🪛 GitHub Check: Lint Code Base

[failure] 142-142:
Missing trailing comma

🪛 GitHub Actions: Pull Request Checks

[error] 142-142: Missing trailing comma (comma-dangle)


Line range hint 136-155: Add error handling for dynamic props loading.

The current implementation lacks error handling for the useQuery hook. Consider adding error handling to:

  1. Handle network failures
  2. Provide feedback to users
  3. Implement retry logic for transient failures
  const {
    isFetching: dynamicPropsQueryIsFetching,
-   // TODO error
+   error,
+   isError,
  } = useQuery({
    queryKey: [
      "dynamicProps",
      queryKeyInput,
    ],
    queryFn: async () => {
      const { dynamicProps } = await client.componentReloadProps(componentReloadPropsInput);
-     // XXX what about if null?
-     // TODO observation errors, etc.
+     if (!dynamicProps) {
+       throw new Error('Failed to load dynamic properties');
+     }
      if (dynamicProps) {
        formProps.onUpdateDynamicProps?.(dynamicProps);
        setDynamicProps(dynamicProps);
      }
      setReloadPropIdx(undefined);
      return []; // XXX ok to mutate above and not look at data?
    },
+   retry: (failureCount, error) => {
+     // Retry up to 3 times for network errors
+     return failureCount < 3 && error instanceof Error;
+   },
+   onError: (error) => {
+     console.error('Failed to load dynamic properties:', error);
+     // Optionally trigger a UI notification
+   },
    enabled: reloadPropIdx != null,
  });
🧰 Tools
🪛 eslint

[error] 142-143: Missing trailing comma.

(comma-dangle)

🪛 GitHub Check: Lint Code Base

[failure] 142-142:
Missing trailing comma

🪛 GitHub Actions: Pull Request Checks

[error] 142-142: Missing trailing comma (comma-dangle)

🧹 Nitpick comments (1)
packages/connect-react/src/hooks/form-context.tsx (1)

132-134: Consider adding type safety and optimizing the query key structure.

While spreading componentReloadPropsInput works, consider:

  1. Creating a dedicated type for the query key
  2. Explicitly selecting only the properties that affect the query result
+type DynamicPropsQueryKey = {
+  userId: string;
+  componentId: string;
+  configuredProps: ConfiguredProps<any>;
+  dynamicPropsId?: string;
+};

-const queryKeyInput = {
-  ...componentReloadPropsInput,
-}
+const queryKeyInput: DynamicPropsQueryKey = {
+  userId,
+  componentId,
+  configuredProps,
+  dynamicPropsId: dynamicProps?.id,
+};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6a99e7 and c3219de.

📒 Files selected for processing (1)
  • packages/connect-react/src/hooks/form-context.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Lint Code Base
packages/connect-react/src/hooks/form-context.tsx

[failure] 142-142:
Missing trailing comma

🪛 GitHub Actions: Pull Request Checks
packages/connect-react/src/hooks/form-context.tsx

[error] 142-142: Missing trailing comma (comma-dangle)

Comment on lines 141 to 142
"dynamicProps",
queryKeyInput
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the missing trailing comma.

Add a trailing comma to maintain consistency with the project's style guide.

    queryKey: [
      "dynamicProps",
-      queryKeyInput
+      queryKeyInput,
    ],
📝 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.

Suggested change
"dynamicProps",
queryKeyInput
"dynamicProps",
queryKeyInput,
🧰 Tools
🪛 GitHub Check: Lint Code Base

[failure] 142-142:
Missing trailing comma

🪛 GitHub Actions: Pull Request Checks

[error] 142-142: Missing trailing comma (comma-dangle)

@bzwrk bzwrk closed this Jan 7, 2025
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.

1 participant