Skip to content

Commit

Permalink
Extending section: prevent duplicate mixin
Browse files Browse the repository at this point in the history
Fixes #6809
  • Loading branch information
distantnative committed Jan 17, 2025
1 parent 2c2e9d1 commit 1e460a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
8 changes: 3 additions & 5 deletions panel/src/components/Sections/ModelsSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@

<script>
import debounce from "@/helpers/debounce";
import section from "@/mixins/section";
export default {
mixins: [section],
inheritAttrs: false,
props: {
blueprint: String,
column: String,
parent: String,
name: String,
timestamp: Number
column: String
},
data() {
return {
Expand Down
1 change: 0 additions & 1 deletion panel/src/mixins/section.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export default {
props: {
blueprint: String,
lock: [Boolean, Object],
help: String,
name: String,
parent: String,
Expand Down
24 changes: 21 additions & 3 deletions panel/src/panel/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,27 @@ export const installComponentMixins = (options) => {
section
};

options.mixins = options.mixins.map((mixin) =>
typeof mixin === "string" ? mixins[mixin] : mixin
);
options.mixins = options.mixins
.map((mixin) => {
// mixin got referenced by name
if (typeof mixin === "string" && mixins[mixin] !== undefined) {
// component inherits from a parent component:
// make sure to only include the mixin if the parent component
// hasn't already included it (to avoid duplicate mixins)
if (options.extends) {
const inherited = new options.extends().$options.mixins ?? [];

if (inherited.includes(mixins[mixin]) === true) {
return;
}
}

return mixins[mixin];
}

return mixin;
})
.filter((mixin) => mixin !== undefined);

return options;
};
Expand Down

0 comments on commit 1e460a8

Please sign in to comment.