Skip to content

refactor(tool-input): replace bidirectional effects with zustand subscription#3215

Merged
waleedlatif1 merged 3 commits intostagingfrom
fix/cancel
Feb 14, 2026
Merged

refactor(tool-input): replace bidirectional effects with zustand subscription#3215
waleedlatif1 merged 3 commits intostagingfrom
fix/cancel

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Replaced two-effect + three-ref bidirectional sync in ToolSubBlockRenderer with a raw Zustand subscription + seed effect + two refs
  • Subscription fires synchronously inside store writes, eliminating the stale-render timing issues that required storeSyncReady hack
  • Removes useSubBlockValue dependency — uses raw store access since SubBlock creates its own hook internally
  • One fewer re-render per keystroke (no intermediate re-render from store subscription)

Type of Change

  • Refactor / improvement

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Feb 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 14, 2026 7:02pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 13, 2026

Greptile Overview

Greptile Summary

This PR is a multi-part change that combines: (1) a refactor of ToolSubBlockRenderer to replace bidirectional effect-based sync with a raw Zustand subscribe() + seed effect pattern, (2) OAuth credential selector positioning improvements in tool-input.tsx, (3) Slack thread_tsthreadTs camelCase rename, (4) cron expression wand support for the Schedule block, and (5) removal of authMethod/destinationType from STRUCTURAL_SUBBLOCK_IDS.

  • Sub-block renderer refactor: The new approach eliminates the useSubBlockValue hook dependency, using direct store subscription and getState().setValue() instead. This reduces re-renders and removes stale-render timing issues. The onParamChangeRef pattern correctly prevents stale closures for the callback.
  • OAuth interleaving: OAuth credential selector is now positioned based on where the oauth-input subblock appears in the block's definition, rather than always being rendered above all parameters. This provides better UX ordering.
  • STRUCTURAL_SUBBLOCK_IDS simplification: Removing authMethod and destinationType is safe because these params have explicit visibility set in tool configs, and blocks without tool-level params (SSH, SFTP) are unaffected since the fallback path skips subblocks without matching tool params.
  • coveredParamIds broadened to allBlockSubBlocks: Prevents hidden subblock-handled params (like authMethod, destinationType) from showing as duplicate uncovered parameter fallback inputs.
  • Slack threadTs rename: Aligns the tool param key with the block's subblock ID, enabling direct subblock-to-param mapping in tool-input rendering. The API route layer still receives thread_ts via the request.body() transform.
  • Cron wand: New cron-expression generation type with prompt and wand route handling, following the established pattern from json-object and timestamp types.

Confidence Score: 4/5

  • This PR is safe to merge with minor risk — the core sync refactor is well-structured, but the broader scope across multiple features means careful manual testing of OAuth flows across different tools is warranted.
  • The Zustand subscription pattern in sub-block-renderer.tsx is correct and simpler than the old bidirectional effects. The syncedRef guards against infinite loops properly. The Slack threadTs rename is consistent across all layers. The STRUCTURAL_SUBBLOCK_IDS change is safe because affected params have explicit visibility. The main risk area is the tool-input.tsx OAuth interleaving logic which is more complex but appears correct. The PR bundles several unrelated changes which makes it harder to review holistically, but each individual change is sound.
  • tool-input.tsx deserves careful manual testing of the OAuth interleaving for tools with and without subblocks, and params.ts should be verified against Elasticsearch tools where authMethod will now be visible.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/components/tools/sub-block-renderer.tsx Replaced bidirectional effect-based sync with Zustand subscription + seed effect. Simpler, fewer refs, eliminates timing issues. Uses onParamChangeRef pattern to avoid stale closures.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx Refactored OAuth credential rendering into position-aware interleaving with subblocks, and extracted renderSubBlock/renderOAuthAccount helpers. Changed coveredParamIds to use allBlockSubBlocks instead of displaySubBlocks. Contains a potential duplicate OAuth rendering issue in the fallback path.
apps/sim/tools/slack/message.ts Renamed thread_ts param to threadTs for camelCase consistency. The request.body() still maps to thread_ts for the API route. Clean rename with no logic changes.
apps/sim/tools/slack/types.ts Renamed thread_ts to threadTs in SlackMessageParams interface. Consistent with the tool param rename.
apps/sim/blocks/blocks/slack.ts Changed thread_ts to threadTs in params() output to match renamed tool param. Consistent with the broader rename.
apps/sim/blocks/blocks/schedule.ts Added wandConfig to cronExpression subblock enabling AI-assisted cron expression generation. Clean addition with appropriate prompt and generationType.
apps/sim/blocks/types.ts Added 'cron-expression' to GenerationType union. Straightforward type extension to support new wand generation type.
apps/sim/tools/params.ts Removed authMethod and destinationType from STRUCTURAL_SUBBLOCK_IDS, making them visible when tool params define visibility. Updated comments. Safe because both params have explicit visibility in tool configs.
apps/sim/app/api/wand/route.ts Added cron-expression generation type handling with instructions to return raw cron expressions without markdown formatting. Follows existing pattern from json-object handling.

Sequence Diagram

sequenceDiagram
    participant User as User Input
    participant SBR as ToolSubBlockRenderer
    participant SBS as useSubBlockStore
    participant TI as ToolInput (handleParamChange)

    Note over SBR: Mount: seed effect runs
    SBR->>SBS: getState().setValue(blockId, syntheticId, toolParamValue)
    SBS-->>SBR: subscribe callback fires (newVal !== oldVal)
    SBR->>SBR: syncedRef guards against echo (stringified === syncedRef)

    Note over User: User types in SubBlock
    User->>SBS: SubBlock writes via setValue()
    SBS-->>SBR: subscribe callback fires synchronously
    SBR->>SBR: Stringify value, check syncedRef
    SBR->>TI: onParamChangeRef.current(toolIndex, paramId, stringified)
    TI->>TI: Updates tool.params[paramId]

    Note over TI: External param change (e.g. wand)
    TI->>SBR: toolParamValue prop changes
    SBR->>SBR: Seed effect: syncedRef = toolParamValue
    SBR->>SBS: getState().setValue(blockId, syntheticId, parsed)
    SBS-->>SBR: subscribe fires, syncedRef guards echo
Loading

Last reviewed commit: d74031c

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review
@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

11 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review
@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

12 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@waleedlatif1 waleedlatif1 merged commit 5b0532d into staging Feb 14, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/cancel branch February 14, 2026 19:19
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