Skip to content

Commit

Permalink
Package exports now used to select between node and browser bundles (#…
Browse files Browse the repository at this point in the history
…156)

Package exports now used to select between node (server-rendering) and browser (client-rendering) bundles
  • Loading branch information
bvaughn authored Jul 1, 2023
2 parents 0328d3a + 4404e42 commit e0c082a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 23 deletions.
25 changes: 25 additions & 0 deletions packages/react-resizable-panels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,30 @@
"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"
Expand All @@ -32,6 +52,11 @@
"#is-development": {
"development": "./src/env-conditions/development.ts",
"default": "./src/env-conditions/production.ts"
},
"#is-browser": {
"browser": "./src/env-conditions/browser.ts",
"node": "./src/env-conditions/node.ts",
"default": "./src/env-conditions/unknown.ts"
}
},
"types": "dist/react-resizable-panels.cjs.d.ts",
Expand Down
12 changes: 5 additions & 7 deletions packages/react-resizable-panels/src/PanelGroup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isBrowser } from "#is-browser";
import { isDevelopment } from "#is-development";
import {
createElement,
Expand Down Expand Up @@ -46,7 +47,6 @@ import {
panelsMapToSortedArray,
} from "./utils/group";
import { loadPanelLayout, savePanelGroupLayout } from "./utils/serialization";
import { isServerRendering } from "./utils/ssr";

const debounceMap: {
[key: string]: (
Expand Down Expand Up @@ -344,12 +344,10 @@ function PanelGroupWithForwardedRef({
// This includes server rendering.
// At this point the best we can do is render everything with the same size.
if (panels.size === 0) {
if (isDevelopment) {
if (isServerRendering() && defaultSize == null) {
console.warn(
`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`
);
}
if (isDevelopment && !isBrowser && defaultSize == null) {
console.warn(
`WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`
);
}

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isBrowser = true;
1 change: 1 addition & 0 deletions packages/react-resizable-panels/src/env-conditions/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isBrowser = false;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isBrowser = typeof window !== "undefined";
11 changes: 2 additions & 9 deletions packages/react-resizable-panels/src/hooks/useIsomorphicEffect.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { isBrowser } from "#is-browser";
import { useLayoutEffect } from "../vendor/react";

const canUseEffectHooks = !!(
typeof window !== "undefined" &&
typeof window.document !== "undefined" &&
typeof window.document.createElement !== "undefined"
);

const useIsomorphicLayoutEffect = canUseEffectHooks
? useLayoutEffect
: () => {};
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : () => {};

export default useIsomorphicLayoutEffect;
7 changes: 0 additions & 7 deletions packages/react-resizable-panels/src/utils/ssr.ts

This file was deleted.

1 comment on commit e0c082a

@vercel
Copy link

@vercel vercel bot commented on e0c082a Jul 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.