Skip to content

bug(vue): useAskableSource enabled option evaluated once at setup — not reactive #268

Closed

Description

@vamgan

Summary

useAskableSource in packages/vue/src/useAskableSource.ts reads options.enabled once at component setup time and never re-evaluates it. If a parent component changes enabled from false to true (or vice versa) after mount, the source registration state does not change.

Root cause

export function useAskableSource(id, source, options = {}) {
  const { enabled = true, ...askableOptions } = options;
  // ...
  if (enabled && sourceId) {           // evaluated ONCE at setup
    handle = ctx.registerSource(sourceId, buildProxy());
    registered = true;
  }
  onUnmounted(unregister);
}

There is no watch on enabled, so toggling it at runtime has no effect.

Expected behaviour

enabled should be watchable. When it changes:

  • false → true: register the source
  • true → false: unregister the source

Fix

watch(
  () => options.enabled ?? true,
  (isEnabled) => {
    if (isEnabled && sourceId && !registered) {
      handle = ctx.registerSource(sourceId, buildProxy());
      registered = true;
    } else if (!isEnabled && registered) {
      unregister();
    }
  },
  { immediate: true }
);

Impact

Any Vue app that conditionally enables/disables a source at runtime will silently fail to register or deregister it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: vueVue adapter workbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions