From 961a1b4e1026bff2bfba72baf267807f8a2c5d7e Mon Sep 17 00:00:00 2001 From: Joey Mezzacappa <20446836+jmezzacappa@users.noreply.github.com> Date: Thu, 6 Jul 2023 13:43:03 -0400 Subject: [PATCH 1/3] Fix label measurement after SSR hydration mismatch Fixes #2625 When React removes the measurement container SVG element from the DOM, label measurements result in `{ width: 0, height: 0 }`. This change verifies that the measurement container is still connected. If not, then a new measurement container is created. --- packages/victory-core/src/victory-util/textsize.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/victory-core/src/victory-util/textsize.ts b/packages/victory-core/src/victory-util/textsize.ts index b41b0b153..3d15347bc 100644 --- a/packages/victory-core/src/victory-util/textsize.ts +++ b/packages/victory-core/src/victory-util/textsize.ts @@ -296,7 +296,11 @@ const styleToKeyComponent = (style) => { const _measureDimensionsInternal = memoize( (text: string | string[], style?: TextSizeStyleInterface) => { - const containerElement = _getMeasurementContainer(); + let containerElement = _getMeasurementContainer(); + if (!containerElement.isConnected) { + _getMeasurementContainer.cache.clear?.(); + containerElement = _getMeasurementContainer(); + } const lines = _splitToLines(text); let heightAcc = 0; From fd98db5250adda21be6092e038eb227d2d62e4c8 Mon Sep 17 00:00:00 2001 From: Joey Mezzacappa <20446836+jmezzacappa@users.noreply.github.com> Date: Thu, 6 Jul 2023 13:58:37 -0400 Subject: [PATCH 2/3] Add changeset --- .changeset/tender-insects-rest.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tender-insects-rest.md diff --git a/.changeset/tender-insects-rest.md b/.changeset/tender-insects-rest.md new file mode 100644 index 000000000..e63202029 --- /dev/null +++ b/.changeset/tender-insects-rest.md @@ -0,0 +1,5 @@ +--- +"victory-core": patch +--- + +Fix label measurements after SSR hydration mismatch From cbd2e5dafed369ad16f8ac238fba65e9795dfd94 Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Mon, 8 Jan 2024 15:06:13 -0600 Subject: [PATCH 3/3] Update changeset to trigger CI --- .changeset/tender-insects-rest.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tender-insects-rest.md b/.changeset/tender-insects-rest.md index e63202029..a6f73b7b6 100644 --- a/.changeset/tender-insects-rest.md +++ b/.changeset/tender-insects-rest.md @@ -2,4 +2,4 @@ "victory-core": patch --- -Fix label measurements after SSR hydration mismatch +Fix text label measurements after SSR hydration mismatch