Skip to content
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

Fix SSR for breadcrumbs and collapsible-nav #3970

Merged
merged 8 commits into from
Sep 2, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fixed bug in `EuiComboBox` where the input was dropping to the next line when a `EuiBadge` had a very long text ([#3968](https://github.com/elastic/eui/pull/3968))
- Fixed type mismatch between `EuiSelectable` options extended via `EuiSelectableOption` and internal option types ([#3983](https://github.com/elastic/eui/pull/3983))
- Fixed `EuiButton` CSS for RTL languages by using `margin-inline-[pos]` instead of `margin-[pos]` ([#3974](https://github.com/elastic/eui/pull/3974))
- Fix server-side rendering of `EuiBreadcrumbs` and `EuiCollapsibleNav` ([#3970](https://github.com/elastic/eui/pull/3970))

## [`28.3.0`](https://github.com/elastic/eui/tree/v28.3.0)

Expand Down
6 changes: 3 additions & 3 deletions src/components/breadcrumbs/breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import React, {
FunctionComponent,
MouseEventHandler,
ReactNode,
useState,
useEffect,
useState,
} from 'react';
import classNames from 'classnames';
import { throttle } from '../color_picker/utils';
Expand All @@ -34,7 +34,7 @@ import { EuiInnerText } from '../inner_text';
import { EuiLink } from '../link';
import { EuiPopover } from '../popover';
import { EuiIcon } from '../icon';
import { getBreakpoint, EuiBreakpointSize } from '../../services/breakpoint';
import { EuiBreakpointSize, getBreakpoint } from '../../services/breakpoint';

export type EuiBreadcrumbResponsiveMaxCount = {
/**
Expand Down Expand Up @@ -187,7 +187,7 @@ export const EuiBreadcrumbs: FunctionComponent<EuiBreadcrumbsProps> = ({
...rest
}) => {
const [currentBreakpoint, setCurrentBreakpoint] = useState(
getBreakpoint(window.innerWidth)
getBreakpoint(typeof window === 'undefined' ? -Infinity : window.innerWidth)
);

const functionToCallOnWindowResize = throttle(() => {
Expand Down
11 changes: 6 additions & 5 deletions src/components/collapsible_nav/collapsible_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
*/

import React, {
cloneElement,
FunctionComponent,
HTMLAttributes,
ReactElement,
ReactNode,
useEffect,
useState,
HTMLAttributes,
ReactElement,
cloneElement,
} from 'react';
import classNames from 'classnames';
import { throttle } from '../color_picker/utils';
import { EuiWindowEvent, keys, htmlIdGenerator } from '../../services';
import { EuiWindowEvent, htmlIdGenerator, keys } from '../../services';
import { EuiFocusTrap } from '../focus_trap';
import { EuiOverlayMask, EuiOverlayMaskProps } from '../overlay_mask';
import { CommonProps } from '../common';
Expand Down Expand Up @@ -95,7 +95,8 @@ export const EuiCollapsibleNav: FunctionComponent<EuiCollapsibleNavProps> = ({
}) => {
const [flyoutID] = useState(id || htmlIdGenerator()('euiCollapsibleNav'));
const [windowIsLargeEnoughToDock, setWindowIsLargeEnoughToDock] = useState(
window.innerWidth >= dockedBreakpoint
(typeof window === 'undefined' ? Infinity : window.innerWidth) >=
dockedBreakpoint
);
const navIsDocked = isDocked && windowIsLargeEnoughToDock;

Expand Down
2 changes: 1 addition & 1 deletion src/services/breakpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const BREAKPOINT_KEYS = keysOf(BREAKPOINTS);
* that is less than or equal to the width
*
* @param {number} width Can either be the full window width or any width
* @param {EuiBreakpoints} breakpoints An object with keys for sizing and values for minimu width
* @param {EuiBreakpoints} breakpoints An object with keys for sizing and values for minimum width
* @returns {string | undefined} Name of the breakpoint key or `undefined` if a key doesn't exist
*/
export function getBreakpoint(
Expand Down