mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 12:33:47 +08:00
This is a reland of f353e8cc4c.
The scroll events logic was flakey; swapping to a polling system which should be
more robust.
Original change's description:
> Fix ElementsBreadcrumbs mutation bugs.
>
> This CL fixes two bugs in the breadcrumbs that were causing too much
> mutation:
>
> 1) Re-creating `NodeText` elements on each render.
> 2) Destroying the scroll buttons and then re-rendering them on every
> scroll.
>
> The first is fixed by using `<devtools-node-text>` and deferring all
> other rendering and instantiation concerns to Lit-Html/the browser. The
> second is fixed by hiding and showing the buttons with CSS. We use the
> new `withNoMutations` unit test helper to ensure we don't mutate and to
> avoid mutations being inadvertently introduced again.
>
> Bug: 1129881
> Change-Id: I17fb517e2eca4761705d604ac34e6404a40b28f8
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2421691
> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Bug: 1129881
Change-Id: I9a2c8cb49c5e60868622a103668d99a9f759053d
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2421700
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import * as LitHtml from '../third_party/lit-html/lit-html.js';
|
|
|
|
const {render, html} = LitHtml;
|
|
|
|
export interface NodeTextData {
|
|
nodeTitle: string, nodeId?: string, nodeClasses?: string[]
|
|
}
|
|
|
|
export class NodeText extends HTMLElement {
|
|
private readonly shadow = this.attachShadow({mode: 'open'});
|
|
private nodeTitle: string = '';
|
|
private nodeId?: string = '';
|
|
private nodeClasses?: string[] = [];
|
|
|
|
set data(data: NodeTextData) {
|
|
this.nodeTitle = data.nodeTitle;
|
|
this.nodeId = data.nodeId;
|
|
this.nodeClasses = data.nodeClasses;
|
|
this.render();
|
|
}
|
|
|
|
private render() {
|
|
const parts = [
|
|
html`<span class="node-label-name">${this.nodeTitle}</span>`,
|
|
];
|
|
|
|
if (this.nodeId) {
|
|
parts.push(html`<span class="node-label-id">#${CSS.escape(this.nodeId)}</span>`);
|
|
}
|
|
|
|
if (this.nodeClasses && this.nodeClasses.length > 0) {
|
|
const text = this.nodeClasses.map(c => `.${CSS.escape(c)}`).join('');
|
|
parts.push(html`<span class="node-label-class">${text}</span>`);
|
|
}
|
|
|
|
// Disabled until https://crbug.com/1079231 is fixed.
|
|
// clang-format off
|
|
render(html`
|
|
<style>
|
|
.node-label-name {
|
|
color: var(--dom-tag-name-color);
|
|
}
|
|
|
|
.node-label-class {
|
|
color: var(--dom-attribute-name-color);
|
|
}
|
|
</style>
|
|
${parts}
|
|
`, this.shadow, {
|
|
eventContext: this,
|
|
});
|
|
// clang-format on
|
|
}
|
|
}
|
|
|
|
customElements.define('devtools-node-text', NodeText);
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'devtools-node-text': NodeText;
|
|
}
|
|
}
|