bvaughn / react-resizable-panels

https://react-resizable-panels.vercel.app/
MIT License
3.87k stars 135 forks source link

Fix incorrect warning for panel defaultSize < minSize #257

Closed beatlevic closed 9 months ago

beatlevic commented 9 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-resizable-panels@1.0.7 for the project I'm working on.

I was getting a constraint warning when the panel was rendered as collapsed on page load. Then it makes sense that the defaultSize is smaller than the minSize. So no need to emit the warning when the defaultSize is the collapsedSize.

Here is the diff that solved my problem:

diff --git a/node_modules/react-resizable-panels/src/utils/validatePanelConstraints.ts b/node_modules/react-resizable-panels/src/utils/validatePanelConstraints.ts
index 58f258c..d78b08a 100644
--- a/node_modules/react-resizable-panels/src/utils/validatePanelConstraints.ts
+++ b/node_modules/react-resizable-panels/src/utils/validatePanelConstraints.ts
@@ -33,7 +33,7 @@ export function validatePanelConstraints({
     if (defaultSize != null) {
       if (defaultSize < 0) {
         warnings.push("default size should not be less than 0");
-      } else if (defaultSize < minSize) {
+      } else if (defaultSize < minSize && defaultSize != collapsedSize) {
         warnings.push("default size should not be less than min size");
       }

This issue body was partially generated by patch-package.

bvaughn commented 9 months ago

That sounds like a reasonable change.

bvaughn commented 9 months ago

Fixed in b27bcfd. Will go out with 1.0.8.

bvaughn commented 9 months ago

This fix just went out with 1.0.8


❤️ → ☕ givebrian.coffee