I recently created a website featuring a tree explorer in a sidebar. However, I encountered an issue with the width calculation of the explorer when toggling the subtrees. This problem specifically arises on Chrome version 111.0.5563.64 for Ubuntu Desktop and can be replicated using the following code snippet.
var [leftEl, rightEl] = (
document.getElementById("grid")
).children;
var tree = `\
node /1
node /1/1
node /1/2
node /1/3
node /1/3/1
node /1/3/2
node /1/3/3
node /2
node /2/1
node /2/2
node /2/3
`;
// Event listeners and other code omitted for brevity
#grid {
height: 100px;
display: grid;
grid-template: 1fr / auto 1fr;
}
// CSS styling properties continued...
<div id="grid">
<div>
<!-- Example -- >
<ul>
<li class="leaf">
<div class="highlighted">node /1</div>
</li>
// More HTML code here...
</ul>
</div>
<div></div>
</div>
The layout consists of two div
elements placed side by side in a grid arrangement.
https://i.sstatic.net/CmRVi.png
The yellow div
element represents the tree explorer positioned on the left. This particular div
needs to be vertically scrollable, as its content may vary in length while maintaining a fixed height.
On the other hand, the blue div
on the right adjusts its width dynamically using the fr
unit. Its content updates based on hover interactions within the tree explorer section.
The width miscalculation issue occurs when the scrollbar of the explorer appears or disappears. The bug's replication process involves:
Expanding "node /1"
https://i.sstatic.net/srBdZ.png
- The yellow
div
's scrollbar becomes visible - A green border indicates text overflow
- The yellow
In trying to resolve this bug, my hypothesis is that the computation sequence relating to container widths might be affected. As per my assumptions, the final state of the scrollbar plays a crucial role at certain stages of calculation. Hence, actions need to be taken to ensure proper consistency during these processes.
- During specific steps, the configuration of the scrollbar causes inconsistencies in computations leading to the bug.
- For other scenarios, where scrollbar status remains stable, computation alignments are correct, thus avoiding issues.
To address this challenge, I implemented a temporary solution involving a click event listener to trigger an immediate update of the blue div
. Although effective, this approach introduces visual glitches and unnecessary reflows, potentially impacting overall performance. Therefore, I am seeking alternative solutions, preferably in pure CSS or HTML, to rectify this bug more efficiently.