Skip to content

feat(sdk) Variable enhancement - #76

Open
szymon-t-sc wants to merge 36 commits into
mainfrom
feat/WB-139-variables
Open

feat(sdk) Variable enhancement #76
szymon-t-sc wants to merge 36 commits into
mainfrom
feat/WB-139-variables

Conversation

@szymon-t-sc

Copy link
Copy Markdown
Member

Workflow Builder introduced variable support some time ago, allowing sidebar controls to use variables from previous nodes or global variables.

This PR enhances the feature with the missing logic to make variable usage more robust and flexible.

Main changes

Variables provided by nodes to downstream nodes can now depend on:

  • selected type in the sidebar - for example, selecting a time-based trigger returns schedule information, while selecting an event-based trigger returns information about the event type
  • sourceHandle - if a node has success and error source handles, it can provide the actual node output to the success branch and the error output to the error-handling branch
Nagranie.z.ekranu.2026-08-14.o.18.32.10.mov

Node variables store:

Previously, variables from previous nodes were calculated when the control was mounted. We traversed the graph and calculated their values at the same time - now we keep nodes variables in the store and only collect them:

  • The list of variables further down the flow is calculated faster, as we only collect the variables that are available
  • It's now easier to check which variables are available from a node, and we can easily add a plugin to display them
obraz

New single variable control (previously used in conditions)

Nagranie.z.ekranu.2026-08-14.o.18.28.48.mov

It shows a date picker with {} when date variables are available.

Fixes

  • When an edge was added or removed, we sometimes had incorrect highlighting of values in controls. This is now fixed thanks to totalVariables
  • Global variables cannot be added in read-only mode

It's worth noting that the majority of the changes are encapsulated in packages/sdk/src/features/variables/. So while reviewing, we can identify what is used externally as a useful public API and note the core functions that could be valuable to expose.

Comment thread apps/demo/src/app/data/nodes/action/action.ts Outdated
@szymon-t-sc
szymon-t-sc marked this pull request as draft August 27, 2026 09:46
@szymon-t-sc
szymon-t-sc marked this pull request as ready for review August 28, 2026 10:09
@szymon-t-sc szymon-t-sc added the enhancement New feature or request label Aug 28, 2026
Comment thread packages/sdk/src/index.ts
Comment thread .changeset/sdk-variables-json-schema.md Outdated
Comment thread apps/docs/src/content/docs/node-schemas/form-controls.md
Comment thread packages/sdk/src/features/variables/hooks/use-node-variables.ts Outdated
return (
<ControlWrapper {...props}>
<DynamicTypedVariableOrInput
key={totalVariables}

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.

key={totalVariables} now remounts a focused input: since suggestions refresh reactively, editing an ancestor while this input is focused changes the count and the remount drops focus, caret, and the open popup

'VariableTextreads suggestions from props each render, so the key looks unnecessary. Remove it here and atvariable-text-control.tsx:39anddependencies.tsx:32`; if the mentions lib truly needs a remount, key off content (join of suggestion ids), not a count, and never while focused.

@szymon-t-sc szymon-t-sc Sep 9, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed total to key. I used total because that was enough in the current setup of the app.

editing an ancestor while this input is focused changes the count and the remount drops focus, caret, and the open popup

We can't change ancestors while the input is focused. The only way we can change ancestors without closing the node sidebar is by drawing an edge, which loses focus by definition.

In the future, when we have multiple people working on the workflow and synchronization that changes ancestors in the background with websockets, we can think about how to keep the focus then. It's just problematic.

The videos below show an artifact/error caused by changing ancestors for a string input in simple textarea, but dynamically typed inputs have {} shown conditionally if there are variables of the selected type. If we have a variable set there and someone removes the list of ancestors, we have another list of edge cases to solve, key just rerenders them again.

I'm open to tackling that, but I would handle it when it actually happens.

if the mentions lib truly needs a remount, key off content (join of suggestion ids), not a count, and never while focused.

One of the problems solved with a key:

Without it
https://github.com/user-attachments/assets/6606ec2f-5222-4c16-8ebe-ca0cb1c2e5b5

With it
https://github.com/user-attachments/assets/c68e03ef-4c49-4fe5-b951-c1942a15442b

Comment thread packages/sdk/src/index.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants