Skip to content

Commit

Permalink
fix(core): fix hydrations issues with animated mount values occasiona…
Browse files Browse the repository at this point in the history
…lly being off
  • Loading branch information
natew committed Dec 28, 2022
1 parent ba88a70 commit 534b7b6
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 26 deletions.
8 changes: 4 additions & 4 deletions apps/site/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ThemeTint, useTint } from '@tamagui/logo'
import { Menu } from '@tamagui/lucide-icons'
import { useRouter } from 'next/router'
import * as React from 'react'
import { TooltipGroup, XGroup } from 'tamagui'
import { Adapt, TooltipGroup, XGroup } from 'tamagui'
import {
Button,
Paragraph,
Expand Down Expand Up @@ -300,16 +300,16 @@ const SmallMenu = React.memo(() => {
</YStack>
</Popover.Trigger>

<Popover.Adapt when="sm">
<Adapt platform="touch" when="sm">
<Popover.Sheet zIndex={100000000} modal dismissOnSnapToBottom>
<Popover.Sheet.Frame>
<Popover.Sheet.ScrollView>
<Popover.Adapt.Contents />
<Adapt.Contents />
</Popover.Sheet.ScrollView>
</Popover.Sheet.Frame>
<Popover.Sheet.Overlay zIndex={100} />
</Popover.Sheet>
</Popover.Adapt>
</Adapt>

<Popover.Content
bw={1}
Expand Down
1 change: 0 additions & 1 deletion packages/adapt/src/Adapt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const AdaptParentContext = createContext<AdaptParentContextI | null>(null
// forward props
export const AdaptContents = (props: any) => {
const context = useContext(AdaptParentContext)
console.log('got', context)
if (!context?.Contents) {
throw new Error('Adapt not supported by this component')
}
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/createComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,17 @@ export function createComponent<
const shouldSetMounted = needsMount && state.unmounted
useEffect(() => {
if (!shouldSetMounted) return
if (state.unmounted === true && needsMount) {
setStateShallow({
unmounted: false,
})
return
}

setStateShallow({
unmounted: false,
})
}, [shouldSetMounted])
}, [shouldSetMounted, state.unmounted])

let styles: Record<string, any>[]

Expand Down
19 changes: 18 additions & 1 deletion packages/core/src/helpers/getSplitStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,24 @@ export const getSplitStyles: StyleSplitter = (
}
}
} else {
const isDisabled = !state[descriptor.stateKey || descriptor.name]
let isDisabled = !state[descriptor.stateKey || descriptor.name]

// we never animate in on server side just show the full thing
// on client side we use CSS to hide the fully in SSR items, then
// un-hide and replay with original animation.
if (!isClient && isEnter) {
isDisabled = false
}

// console.log(
// 'isDisabled',
// state,
// descriptor.stateKey,
// state[descriptor.stateKey || descriptor.name],
// isDisabled,
// descriptor
// )

if (!isDisabled) {
usedKeys[key] ||= 1
}
Expand Down
6 changes: 3 additions & 3 deletions packages/sheet/src/Sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const Sheet = withStaticProperties(
/**
* Performance is sensitive here so avoid all the hooks below with this
*/
if (isShowingNonSheet && hydrated !== false) {
if (isShowingNonSheet || !hydrated) {
return null
}

Expand Down Expand Up @@ -638,14 +638,14 @@ const SheetImplementation = themeable(
{handleComponent}

<RemoveScroll
forwardProps
enabled={removeScrollEnabled}
as={Slot}
allowPinchZoom
shards={[contentRef]}
// causes lots of bugs on touch web on site
removeScrollBar={false}
>
{isResizing ? null : frameComponent}
{isResizing ? <></> : frameComponent}
</RemoveScroll>
</AnimatedView>
</SheetProvider>
Expand Down
2 changes: 1 addition & 1 deletion packages/static/src/extractor/babelParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export function babelParse(code: string | Buffer): t.File {
try {
return parser(code.toString(), parserOptions) as any
} catch (err) {
console.log(`Error parsing babel: ${err} in code`)
throw new Error(`Error parsing babel: ${err} in code`)
}
}
14 changes: 1 addition & 13 deletions packages/static/types/extractor/createExtractor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@ export declare function createExtractor({ logger }?: ExtractorOptions): {
cleanupBeforeExit: typeof cleanupBeforeExit;
loadTamagui: (props: TamaguiOptions) => Promise<TamaguiProjectInfo>;
loadTamaguiSync: (props: TamaguiOptions) => TamaguiProjectInfo;
getTamagui(): import("@tamagui/core-node").TamaguiInternalConfig<import("@tamagui/core-node").CreateTokens<import("@tamagui/core-node").VariableVal>, {
[key: string]: Partial<import("@tamagui/core-node").TamaguiBaseTheme> & {
[key: string]: import("@tamagui/core-node").VariableVal;
};
}, import("@tamagui/core-node").GenericShorthands, {
[key: string]: {
[key: string]: string | number;
};
}, {
[key: string]: string | any[] | {
[key: string]: any;
};
}, import("@tamagui/core-node").GenericFonts> | undefined;
getTamagui(): any;
parseSync: (f: FileOrPath, props: ExtractorParseProps) => {
styled: number;
flattened: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/static/types/extractor/extractHelpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export declare function isValidThemeHook(props: TamaguiOptionsWithFileInfo, jsxP
export declare const isInsideComponentPackage: (props: TamaguiOptionsWithFileInfo, moduleName: string) => any;
export declare const isComponentPackage: (props: TamaguiOptionsWithFileInfo, srcName: string) => any;
export declare function getValidComponent(props: TamaguiOptionsWithFileInfo, moduleName: string, componentName: string): false | {
staticConfig: import("@tamagui/core-node").StaticConfigParsed;
staticConfig: StaticConfigParsed;
} | null;
export declare const isValidModule: (props: TamaguiOptionsWithFileInfo, moduleName: string) => {
isLocal: boolean;
isValid: any;
};
export declare const getValidImport: (props: TamaguiOptionsWithFileInfo, moduleName: string, componentName?: string) => {
staticConfig: import("@tamagui/core-node").StaticConfigParsed;
staticConfig: StaticConfigParsed;
} | null;
export declare const isValidImport: (props: TamaguiOptionsWithFileInfo, moduleName: string, componentName?: string) => any;
//# sourceMappingURL=extractHelpers.d.ts.map

1 comment on commit 534b7b6

@vercel
Copy link

@vercel vercel bot commented on 534b7b6 Dec 28, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

site – ./

site-tamagui.vercel.app
site-git-master-tamagui.vercel.app
site-beta-beige.vercel.app

Please sign in to comment.