Skip to content

Stellar exported app: Connect Wallet resets form inputs #175

@pasevin

Description

@pasevin

Summary

In exported apps using the Stellar adapter, clicking "Connect Wallet" causes the entire form to reset/clear. This does not happen in the builder form preview.

Repro Steps

  1. In the Builder, configure a Stellar contract form and export the app.
  2. Run the exported app (e.g., pnpm install && pnpm dev).
  3. Fill in some form fields.
  4. Click "Connect Wallet" and select a Stellar wallet.

Expected

  • Connecting a wallet should not clear any filled form inputs.

Actual

  • The form resets and all fields are cleared after clicking "Connect Wallet" (or immediately after connect).

Scope / Observations

  • Observed only in exported apps using the Stellar adapter.
  • Builder form preview does not reset.
  • Likely affects any exported app if the schema object is recreated per render (adapter-agnostic root cause), though the regression is currently reported for Stellar.

Diagnosis (Preliminary)

TransactionForm resets when the schema reference changes. In the exported app, the generated GeneratedForm component creates formSchema and contractSchema inline inside the component function, so they get a new identity on every render. Any re-render (e.g., wallet connection state change) therefore triggers a reset.

Relevant code behavior in the renderer:

// TransactionForm: resets on schema reference changes
useEffect(() => {
  methods.reset(createDefaultFormValues(schema.fields, schema.defaultValues));
  setTxStatus('idle');
  setTxHash(null);
  setTxError(null);
  setFormError(null);
  setExecutionConfigError(null);
}, [schema, methods]);

Relevant snippet from the exported GeneratedForm template (simplified for illustration):

export default function GeneratedForm({ adapter, isWalletConnected }: GeneratedFormProps) {
  const formSchema: RenderFormSchema = {/* generated JSON */};
  const contractSchema: ContractSchema = {/* generated JSON */};
  return (
    <TransactionForm
      schema={formSchema}
      contractSchema={contractSchema}
      adapter={adapter}
      isWalletConnected={isWalletConnected}
      executionConfig={executionConfig}
    />
  );
}

In the Builder preview, the schema is memoized with useMemo, so identity is stable across re-renders.

Proposed Fix

Ensure generated objects have a stable identity across renders in packages/builder/src/export/codeTemplates/form-component.template.tsx:

  • Option A (preferred): hoist generated objects to module scope (top-level constants) and reference them inside the component.
  • Option B: wrap with useMemo(() => CONST, []) inside the component.

Example (illustrative diff):

- export default function GeneratedForm(...) {
-   const formSchema: RenderFormSchema = /*@@FORM_SCHEMA_JSON@@*/;
-   const contractSchema: ContractSchema = /*@@CONTRACT_SCHEMA_JSON@@*/;
-   const executionConfig: ExecutionConfig | undefined = /*@@EXECUTION_CONFIG_JSON@@*/;
-   ...
- }
+ const FORM_SCHEMA: RenderFormSchema = /*@@FORM_SCHEMA_JSON@@*/;
+ const CONTRACT_SCHEMA: ContractSchema = /*@@CONTRACT_SCHEMA_JSON@@*/;
+ const EXECUTION_CFG: ExecutionConfig | undefined = /*@@EXECUTION_CONFIG_JSON@@*/;
+
+ export default function GeneratedForm(...) {
+   const formSchema = FORM_SCHEMA;
+   const contractSchema = CONTRACT_SCHEMA;
+   const executionConfig = EXECUTION_CFG;
+   ...
+ }

This guarantees stable references across re-renders and prevents unintended resets.

Workaround

Connect the wallet before filling the form (not ideal for UX).

Acceptance Criteria

  • Form inputs are preserved across wallet connect/disconnect and related state changes in exported Stellar apps.
  • No resets occur unless the schema content actually changes.

Notes

  • Both Builder and exported apps use React StrictMode; this is not the cause here.
  • Fix likely benefits all ecosystems; this issue tracks the Stellar export regression observed by users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstellarStellar Ecosystem Related Issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions