# modifyClass failed with a warning

**URL:** https://meta.discourse.org/t/modifyclass-failed-with-a-warning/239535
**Category:** Development
**Created:** [September 20, 2022, 10:45am UTC](https://meta.discourse.org/t/modifyclass-failed-with-a-warning/239535 "2022-09-20T10:45:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [September 20, 2022, 10:45am UTC](https://meta.discourse.org/t/modifyclass-failed-with-a-warning/239535/1 "2022-09-20T10:45:46Z")

</div>

Hello！  
I want to modify controller with plugin api, but it failed with a warning like:

[THEME xxx] “controller:full-page-search” was already cached in the container. Changes won’t be applied.

my code:

```js
function modifySearchTypes(api) {
    api.modifyClass("controller:full-page-search", {
        pluginId: "modify-search-types",
        init() {
            this._super(...arguments);
            
        
            this.set("searchTypes", [
              { name: I18n.t("search.type.default"), id: SEARCH_TYPE_DEFAULT },
              {
                name: this.siteSettings.tagging_enabled
                  ? I18n.t("search.type.categories_and_tags")
                  : I18n.t("search.type.categories"),
                id: SEARCH_TYPE_CATS_TAGS,
              },
            ]);
            this.selected = [];
        },
    });
}

export default {
    name: "modify-search-types",
    initialize() {     
        withPluginApi("0.10.0", modifySearchTypes);
    },
};

```

How can I deal with it?  
Thank you very much!

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [September 20, 2022, 12:26pm UTC](https://meta.discourse.org/t/modifyclass-failed-with-a-warning/239535/2 "2022-09-20T12:26:24Z")

</div>

See [api.modifyClass sometimes(!) not working - #12 by RGJ](https://meta.discourse.org/t/api-modifyclass-sometimes-not-working/212413/12)

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [September 20, 2022, 12:32pm UTC](https://meta.discourse.org/t/modifyclass-failed-with-a-warning/239535/3 "2022-09-20T12:32:19Z")

</div>

> [@RGJ](#):
>
> api.modifyClass 有时（！）不起作用 - RGJ 的 #12

Thank you!  
However, code below still failed and print this warning.

```js
function modifySearchTypes(api) {
    api.modifyClass("controller:full-page-search", {
        pluginId: "modify-search-types",
        init() {
            this._super(...arguments);
            
        
            this.set("searchTypes", [
              { name: I18n.t("search.type.default"), id: SEARCH_TYPE_DEFAULT },
              {
                name: this.siteSettings.tagging_enabled
                  ? I18n.t("search.type.categories_and_tags")
                  : I18n.t("search.type.categories"),
                id: SEARCH_TYPE_CATS_TAGS,
              },
            ]);
            this.selected = [];
        },
    });
   const searchController = api.container.lookup("controller:full-page-search");
}

export default {
    name: "modify-search-types",
    initialize() {     
        withPluginApi("0.10.0", modifySearchTypes);
    },
};

```

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [September 20, 2022, 12:39pm UTC](https://meta.discourse.org/t/modifyclass-failed-with-a-warning/239535/4 "2022-09-20T12:39:08Z")

</div>

In that case, I have no idea.

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [September 20, 2022, 12:50pm UTC](https://meta.discourse.org/t/modifyclass-failed-with-a-warning/239535/5 "2022-09-20T12:50:06Z")

</div>

I override template of full page search with a new one in my theme component. Does it have any effect？

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [April 18, 2023, 10:40am UTC](https://meta.discourse.org/t/modifyclass-failed-with-a-warning/239535/6 "2023-04-18T10:40:06Z")

</div>

> [@Using modifyClass to change core behavior](https://meta.discourse.org/t/using-modifyclass-for-objects-which-are-initialized-early-in-boot/262064):
>
> For advanced themes and plugins, Discourse offers the modifyClass system. This allows you to extend and override functionality in many of core’s javascript classes. When to use modifyClass modifyClass should be a last resort, when your customization cannot be made via Discourse’s more stable customization APIs (e.g. plugin-api methods, plugin outlets, transformers). Core’s code can change at any time. And therefore, customizations made via modifyClass could break at any time. When using this A…

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [April 18, 2023, 10:40am UTC](https://meta.discourse.org/t/modifyclass-failed-with-a-warning/239535/7 "2023-04-18T10:40:10Z")

</div>


