Skip to content

Dependent autocomplete (params) clears its value on load when the form opens with pre-existing values #31

@stmh

Description

@stmh

Summary

A format: "autocomplete" field that declares a dependency via autocomplete.params loses its own value whenever the form is opened/loaded with values already populated (e.g. editing a saved record/node). The dependent field is cleared to '' before the user can save, so the value never round-trips.

Fields without params (non-dependent autocompletes) are unaffected.

Version: @flowdrop/flowdrop@1.13.0

Root cause

Both host forms initialise their internal values empty and only fill them from the values/config prop in a post-mount $effect:

  • SchemaForm.svelteformValues = $state({}) then merge effect (Object.entries(schema.properties)...; formValues = mergedValues)
  • ConfigForm.svelteconfigValues = $state({}) then merge effect (... configValues = mergedConfig)

Both expose the live state via setContext('flowdrop:getFormValues', () => …).

In FormAutocomplete.svelte:

// captured during component init — getFormValues() is still {} at this point
let prevDepFingerprint = depFingerprint;   // => "{}"

$effect(() => {
  const current = depFingerprint;
  if (current === prevDepFingerprint) return;
  prevDepFingerprint = current;
  abortController?.abort();
  suggestions = [];
  labelCache = new Map();
  if (multiple) onChange([]);
  else onChange('');           // <-- wipes the dependent field's value
});

Mount/effect ordering (parent before child on initial flush):

  1. Host form sets formValues = {}; children render.
  2. Dependent FormAutocomplete captures prevDepFingerprint from the empty form → "{}".
  3. Host form's merge $effect runs and populates the dependency value.
  4. The dependent field's fingerprint flips "{}"{"<param>":"<value>"}, the clearing effect fires, and onChange('') wipes the just-loaded value.

Reproduction

  1. Build a SchemaForm (or ConfigForm) with two autocomplete fields where field B declares autocomplete.params: { someParam: "fieldA" }.
  2. Mount it with values that already contain both fieldA and fieldB.
  3. Observe that fieldB is cleared to '' shortly after mount, even though no user interaction occurred.

This also affects node configs in the editor: a saved node with a dependent autocomplete (e.g. a Jira create_issue node with issue_type, which depends on account/project) loses the dependent value when reopened. It typically goes unnoticed because nodes are usually filled from scratch (dependency-then-dependent), where clearing an already-empty field is a harmless no-op.

Expected behaviour

A dependent autocomplete should preserve its incoming value when the form loads. The clearing-on-dependency-change behaviour should only apply to a genuine user-driven change of the dependency, not to the initial empty→populated transition during form initialisation.

Suggested fix

Skip the clear when the fingerprint's first transition is from the empty-initial state — e.g. initialise prevDepFingerprint lazily once the host form's values have settled, or guard the clearing effect so it doesn't run on the initial "{}" → populated transition (only clear when the previous fingerprint was itself non-empty / derived from a real value).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions