|
| 1 | +import { type Component, createSignal } from "solid-js"; |
| 2 | +import uPlot from "uplot"; |
| 3 | + |
| 4 | +import { SolidUplot } from "../../src/SolidUplot"; |
| 5 | + |
| 6 | +const generateData = (): uPlot.AlignedData => { |
| 7 | + const length = 10; |
| 8 | + const x = Array.from({ length }, (_, i) => i); |
| 9 | + const y = Array.from({ length }, () => Math.random() * 100); |
| 10 | + return [x, y]; |
| 11 | +}; |
| 12 | + |
| 13 | +/** |
| 14 | + * Regression test page for the infinite height growth bug fix. |
| 15 | + * This page is NOT linked in the sidebar - access via direct URL only. |
| 16 | + * |
| 17 | + * Previously, when autoResize was enabled in an unconstrained container (no explicit height), |
| 18 | + * the chart would enter a feedback loop where it kept growing indefinitely. |
| 19 | + * |
| 20 | + * The fix uses `flex: 1 1 0` with `min-height: 0` on the chart container, which prevents |
| 21 | + * the chart from forcing parent height growth while still filling available space. |
| 22 | + * |
| 23 | + * Both scenarios below should now maintain stable heights. |
| 24 | + */ |
| 25 | +export const ResizeBugTest: Component = () => { |
| 26 | + const [data] = createSignal(generateData()); |
| 27 | + |
| 28 | + return ( |
| 29 | + <div class="p-8"> |
| 30 | + <h1 class="mb-4 text-2xl font-bold">Resize Regression Test Page</h1> |
| 31 | + <p class="mb-8 text-gray-600"> |
| 32 | + This page verifies the fix for the infinite height growth bug when using autoResize. Both |
| 33 | + scenarios below should maintain stable heights. Access via direct URL only. |
| 34 | + </p> |
| 35 | + |
| 36 | + {/* Previously Bug Case: Unconstrained container - now fixed */} |
| 37 | + <section class="mb-8"> |
| 38 | + <h2 class="mb-2 text-lg font-semibold text-blue-700"> |
| 39 | + Unconstrained Container (Previously Buggy - Now Fixed) |
| 40 | + </h2> |
| 41 | + <p class="mb-2 text-sm text-blue-600"> |
| 42 | + This container has no height constraint. Previously this caused infinite growth, but the |
| 43 | + fix prevents the chart from forcing parent height growth. |
| 44 | + </p> |
| 45 | + <div data-testid="unconstrained-container"> |
| 46 | + <SolidUplot |
| 47 | + autoResize |
| 48 | + data={data()} |
| 49 | + series={[{}, { label: "Series", stroke: "#3b82f6", width: 2 }]} |
| 50 | + scales={{ x: { time: false } }} |
| 51 | + childrenPlacement="top" |
| 52 | + > |
| 53 | + <div |
| 54 | + style={{ |
| 55 | + height: "50px", |
| 56 | + background: "#dbeafe", |
| 57 | + padding: "8px", |
| 58 | + display: "flex", |
| 59 | + "align-items": "center", |
| 60 | + "justify-content": "center", |
| 61 | + }} |
| 62 | + > |
| 63 | + Child content that adds height |
| 64 | + </div> |
| 65 | + </SolidUplot> |
| 66 | + </div> |
| 67 | + </section> |
| 68 | + |
| 69 | + {/* Safe Case: Constrained container */} |
| 70 | + <section> |
| 71 | + <h2 class="mb-2 text-lg font-semibold text-green-700">Constrained Container</h2> |
| 72 | + <p class="mb-2 text-sm text-green-600"> |
| 73 | + This container has explicit height (400px) - autoResize fills the available space |
| 74 | + correctly. |
| 75 | + </p> |
| 76 | + <div |
| 77 | + data-testid="constrained-container" |
| 78 | + style={{ height: "400px", border: "2px dashed #22c55e" }} |
| 79 | + > |
| 80 | + <SolidUplot |
| 81 | + autoResize |
| 82 | + data={data()} |
| 83 | + series={[{}, { label: "Series", stroke: "#22c55e", width: 2 }]} |
| 84 | + scales={{ x: { time: false } }} |
| 85 | + childrenPlacement="top" |
| 86 | + > |
| 87 | + <div |
| 88 | + style={{ |
| 89 | + height: "50px", |
| 90 | + background: "#dcfce7", |
| 91 | + padding: "8px", |
| 92 | + display: "flex", |
| 93 | + "align-items": "center", |
| 94 | + "justify-content": "center", |
| 95 | + }} |
| 96 | + > |
| 97 | + Child content that adds height |
| 98 | + </div> |
| 99 | + </SolidUplot> |
| 100 | + </div> |
| 101 | + </section> |
| 102 | + </div> |
| 103 | + ); |
| 104 | +}; |
0 commit comments