[IMP] web: don't observe immutable objects in command palette

This improves rendering performance when there are a lot of command
items.

closes odoo/odoo#84303

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Samuel Degueldre
2022-02-10 10:49:43 +00:00
parent 50f4af252c
commit 89f6d64d06
@@ -9,7 +9,7 @@ import { fuzzyLookup } from "@web/core/utils/search";
import { debounce } from "@web/core/utils/timing";
import { escapeRegExp } from "../utils/strings";
const { Component, onWillStart, useRef, useState } = owl;
const { Component, onWillStart, useRef, useState, markRaw } = owl;
const DEFAULT_PLACEHOLDER = _lt("Search...");
const DEFAULT_EMPTY_MESSAGE = _lt("No result found");
@@ -178,11 +178,13 @@ export class CommandPalette extends Component {
}
}
this.state.commands = commands.map((command) => ({
...command,
keyId: this.keyId++,
splitName: splitCommandName(command.name, options.searchValue),
}));
this.state.commands = markRaw(
commands.map((command) => ({
...command,
keyId: this.keyId++,
splitName: splitCommandName(command.name, options.searchValue),
}))
);
this.selectCommand(this.state.commands.length ? 0 : -1);
this.mouseSelectionActive = false;
this.state.emptyMessage =
@@ -195,7 +197,7 @@ export class CommandPalette extends Component {
this.state.selectedCommand = null;
return;
}
this.state.selectedCommand = this.state.commands[index];
this.state.selectedCommand = markRaw(this.state.commands[index]);
}
selectCommandAndScrollTo(type) {