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: do not use useLayoutEffect on SSR #2140

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/Field/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"@welcome-ui/field-group": "^5.0.0-alpha.41",
"@welcome-ui/hint": "^5.0.0-alpha.40",
"@welcome-ui/label": "^5.0.0-alpha.41",
"@welcome-ui/system": "^5.0.0-alpha.40"
"@welcome-ui/system": "^5.0.0-alpha.40",
"@welcome-ui/utils": "^5.0.0-alpha.37"
},
"peerDependencies": {
"@xstyled/styled-components": "^3.7.3",
Expand Down
5 changes: 3 additions & 2 deletions packages/Field/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Fragment, useLayoutEffect } from 'react'
import React, { Fragment } from 'react'
import { Label } from '@welcome-ui/label'
import { Hint } from '@welcome-ui/hint'
import { CreateWuiProps, forwardRef } from '@welcome-ui/system'
import { useIsomorphicLayoutEffect } from '@welcome-ui/utils'

// Fields
import { RowContainer } from './layout'
Expand Down Expand Up @@ -66,7 +67,7 @@ export const Field = forwardRef<'div', FieldProps>(
...(isGroup ? { flexDirection: layout } : {}),
})

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
Object.keys(children.props).forEach(prop => {
if (forwardedProps.includes(prop)) {
const element = document.getElementById(htmlFor)
Expand Down
1 change: 1 addition & 0 deletions packages/Popover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@welcome-ui/button": "^5.0.0-alpha.40",
"@welcome-ui/icons": "^5.0.0-alpha.41",
"@welcome-ui/system": "^5.0.0-alpha.40",
"@welcome-ui/utils": "^5.0.0-alpha.37",
"reakit": "^1.3.11"
},
"peerDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions packages/Popover/src/Trigger.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CreateWuiProps, forwardRef } from '@welcome-ui/system'
import React, { useLayoutEffect, useRef } from 'react'
import React, { useRef } from 'react'
import { useIsomorphicLayoutEffect } from '@welcome-ui/utils'

import { UsePopoverStateReturn } from './usePopoverState'
import * as S from './styles'
Expand Down Expand Up @@ -48,7 +49,7 @@ export const Trigger = forwardRef<'button', TriggerProps>(({ as, state, ...rest
}
}

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
const disclosure = disclosureRef.current
if (hoverable && disclosure) {
// add listeners on mount
Expand Down
6 changes: 4 additions & 2 deletions packages/Tabs/src/ActiveBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useLayoutEffect, useState } from 'react'
import React, { useState } from 'react'
import { useViewportSize } from '@welcome-ui/utils'
import { TabStateReturn } from 'reakit'
import { useIsomorphicLayoutEffect } from '@welcome-ui/utils'

import * as S from './styles'

Expand All @@ -17,7 +18,8 @@ function useActiveBarState(
): ActiveBarStateReturn {
const [state, setState] = useState({})
const { height: viewportHeight, width: viewportWidth } = useViewportSize()
useLayoutEffect(() => {

useIsomorphicLayoutEffect(() => {
const list = listRef.current
if (!list || !activeTab) return

Expand Down
1 change: 1 addition & 0 deletions packages/Tooltip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"dependencies": {
"@welcome-ui/box": "^5.0.0-alpha.40",
"@welcome-ui/system": "^5.0.0-alpha.40",
"@welcome-ui/utils": "^5.0.0-alpha.37",
"popper.js": "^1.16.1",
"reakit": "^1.3.11"
},
Expand Down
12 changes: 3 additions & 9 deletions packages/Tooltip/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import React, {
cloneElement,
useCallback,
useEffect,
useLayoutEffect,
useRef,
useState,
} from 'react'
import React, { cloneElement, useCallback, useEffect, useRef, useState } from 'react'
import Popper, { Placement } from 'popper.js'
import { TooltipReference, useTooltipState } from 'reakit'
import { useDialogState } from 'reakit'
import { CreateWuiProps, forwardRef } from '@welcome-ui/system'
import { Box } from '@welcome-ui/box'
import { useIsomorphicLayoutEffect } from '@welcome-ui/utils'

import * as S from './styles'

Expand Down Expand Up @@ -49,7 +43,7 @@ const useMouseTooltipState = ({
}
}, [originalPlacement, dialog.visible])

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
createPopper()
return () => {
if (popper.current) {
Expand Down
6 changes: 4 additions & 2 deletions packages/Utils/src/use-viewport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useLayoutEffect, useState } from 'react'
import { useState } from 'react'

import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect'

type Size = {
height: number
Expand All @@ -8,7 +10,7 @@ type Size = {
export function useViewportSize(): Size {
const [size, setSize] = useState<Size>({ height: undefined, width: undefined })

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
setSize({ width: window.innerWidth, height: window.innerHeight })

function handleResize() {
Expand Down