Topic footer button dependentKeys not working

I have problems getting dependentKeys to work in registerTopicFooterButton (documented here)

My code (minimal example)

  api.registerTopicFooterButton({
    id: "my-topic-footer-button",
    action() {
      this.topic.updateTags(["my-tag"]);
    },
    title() {
      return "my.button.title";
    },
    label() {
      return "my.button.label";
    },
    dependentKeys: ["topic.tags"],
    disabled() {
      return this.topic.tags.includes("my-tag");
    }
  });

Expected: once I press the button, the tags for the topic are set to my-tag (works), which triggers a re-render of the button, and disables it.
Expected: once I add the tag manually, the button is disabled

Reality: the re-render is not triggered in either scenario.

The button is correctly disabled/enabled on page refresh.

Anyone who can spot my error?

1 Like

Having a computed property depending on topic.tags will cause it to be invalidated when the array itself is replaced. But it won’t cause invalidation when items are added/removed from the array.

So I think you probably want topic.tags.@each (docs).

In general we’re trying to move away from computed properties, and towards native-getters/autotracking. I guess we’ll have to modernize the topic-footer-buttons API at some point to support that :thinking:

2 Likes

Thank you for the really fast response David!

However, using topic.tags.@each does not resolve this… (either way, not when the tag is added manually, not when the button is pressed).

A console.log in the disabled() function does not run. It doesn’t run in displayed() either.

1 Like

When you click your button, does the new tag show up correctly at the top of the topic?

1 Like

Yes, that works fine.

I also tried this.topic.notifyPropertyChange("tags");

and I even went desperate and tried to manipulate other properties (like this.topic.title = this.topic.title + "!" and including topic.title in dependentKeys). That does not work either. Using this.topic.set... doesn’t work as well.

1 Like

Interestingly, if I copy/paste your example from the OP and run locally, it seems to work perfectly:

Are there any other themes/plugins which could be interfering? Or perhaps something different about your ā€˜real’ code, compared to the minimal example in the OP?

:thinking:

My ā€œminimalā€ code in the OP is my ā€œrealā€ code at the moment. I’m going to move it to a completely clean install and see if that changes anything.

EDIT yes it does work on a clean install :sob: :sob:

I’ll unlist this topic so I don’t have to live with the shame :wink:
I’ll update you when I find out what was causing this.

Thank you for your help @david!!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.