-
-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use static exports conditions to select node and browser code #156
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -0,0 +1 @@ | |||
export const isBrowser = typeof window !== "undefined"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kinda should almost never be even chosen but better to be safe than sorry, right? :p
"#is-browser": { | ||
"browser": "./src/env-conditions/browser.ts", | ||
"node": "./src/env-conditions/node.ts", | ||
"default": "./src/env-conditions/unknown.ts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like most of this stuff! and I appreciate you trying things out and sharing ideas too!
My main concern here is that this is getting pretty large and easy to mess up. One conditional is 🤷🏼 but two is a lot worse 😁
react-resizable-panels/packages/react-resizable-panels/package.json
Lines 14 to 50 in f303d95
"exports": { | |
".": { | |
"types": { | |
"import": "./dist/react-resizable-panels.cjs.mjs", | |
"default": "./dist/react-resizable-panels.cjs.js" | |
}, | |
"development": { | |
"browser": { | |
"module": "./dist/react-resizable-panels.browser.development.esm.js", | |
"import": "./dist/react-resizable-panels.browser.development.cjs.mjs", | |
"default": "./dist/react-resizable-panels.browser.development.cjs.js" | |
}, | |
"node": { | |
"module": "./dist/react-resizable-panels.development.node.esm.js", | |
"import": "./dist/react-resizable-panels.development.node.cjs.mjs", | |
"default": "./dist/react-resizable-panels.development.node.cjs.js" | |
}, | |
"module": "./dist/react-resizable-panels.development.esm.js", | |
"import": "./dist/react-resizable-panels.development.cjs.mjs", | |
"default": "./dist/react-resizable-panels.development.cjs.js" | |
}, | |
"browser": { | |
"module": "./dist/react-resizable-panels.browser.esm.js", | |
"import": "./dist/react-resizable-panels.browser.cjs.mjs", | |
"default": "./dist/react-resizable-panels.browser.cjs.js" | |
}, | |
"node": { | |
"module": "./dist/react-resizable-panels.node.esm.js", | |
"import": "./dist/react-resizable-panels.node.cjs.mjs", | |
"default": "./dist/react-resizable-panels.node.cjs.js" | |
}, | |
"module": "./dist/react-resizable-panels.esm.js", | |
"import": "./dist/react-resizable-panels.cjs.mjs", | |
"default": "./dist/react-resizable-panels.cjs.js" | |
}, | |
"./package.json": "./package.json" | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish there was a more compact way to define/manage this.
const useIsomorphicLayoutEffect = canUseEffectHooks | ||
? useLayoutEffect | ||
: () => {}; | ||
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : () => {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice.
I'm on the fence about this. It's nice overall, except for the |
I think that this kinda boils down to what you, as a maintainer, are comfortable with. I certainly see how the To quote Sebastian's thoughts from this comment:
|
I'm still struggling a bit with how to use these new conditions (e.g. bvaughn/suspense#35) so I'm a little wary to add more. I'll leave this open for the time being and keep thinking on it. |
i’ll try to take a look at this over the weekend |
As always I would appreciate your input, but please, only do that if you're personally curious. |
I've let this sit in the back of my mind for a while, and while I don't like the bloat it adds to |
f303d95
to
4404e42
Compare
This PR is really just me tinkering with settings and stuff to get a better feeling about what's possible and how this can look like. Since I already tinkered with it locally, I figured out I can share it publicly here as well.
In this library though... this is really on the verge of micro-optimization though because we literally shave just a couple of bytes in production mode. I wonder though if there is something to be gained by wrapping all effects with
isBrowser
check. That could remove quite a bit of redundant code in node: less code parsing, less execution while SSRing, profit (?).Feel free to close it right away.