iamkun / iamkun/dayjs

Format causes crash on save in React Native

Open
#2,292 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
Using `dayjs().format(foo)` causes the app to crash, but only when saving.
When reloading the app, everything loads fine.

If I remove `.format(foo)` and replace it with some other string generating function the application behaves as expected.

Here's the code:
```ts
import React from 'react';
import dayjs from 'dayjs';
import {Text, TextProps} from '@ui-kitten/components';

interface TimeStampProps extends TextProps {
date?: string | number | dayjs.Dayjs | Date | null;
format: string;
}

const TimeStamp = ({date, format, ...props}: TimeStampProps) => {
const text = dayjs(date).format(format);
return {text};
};

export default React.memo(TimeStamp);
```

The app crashes with the following simulator image

image

and the following stack trace:

```
ERROR TypeError: Cannot convert undefined value to object

This error is located at:
in TimeStamp (created by DashboardScreen)
in RCTView (created by View)
in View (created by Layout)
in Layout
in Wrapper (created by Layout)
in WrappingElement (created by DefaultLayout)
in RCTView (created by View)
in View (created by DefaultLayout)
in RCTScrollContentView (created by ScrollView)
in RCTScrollView (created by ScrollView)
in ScrollView (created by ScrollView)
in ScrollView (created by DefaultLayout)
in TouchableWithoutFeedback (created by DefaultLayout)
in RCTView (created by View)
in View (created by KeyboardAvoidingView)
in KeyboardAvoidingView (created by DefaultLayout)
in RCTView (created by View)
in View (created by DefaultLayout)
in DefaultLayout (created by DashboardScreen)
in DashboardScreen (created by SceneView)
in StaticContainer
in EnsureSingleNavigator (created by SceneView)
in SceneView (created by SceneView)
in RCTView (created by View)
in View (created by DebugContainer)
in DebugContainer (created by MaybeNestedStack)
in MaybeNestedStack (created by SceneView)
in RCTView (created by View)
in View (created by SceneView)
in RNSScreen (created by AnimatedComponent)
in AnimatedComponent
in AnimatedComponentWrapper (created by InnerScreen)
in Suspender (created by Freeze)
in Suspense (created by Freeze)
in Freeze (created by DelayedFreeze)
in DelayedFreeze (created by InnerScreen)
in InnerScreen (created by Screen)
in Screen (created by SceneView)
in SceneView (created by NativeStackViewInner)
in Suspender (created by Freeze)
in Suspense (created by Freeze)
in Freeze (created by DelayedFreeze)
in DelayedFreeze (created by ScreenStack)
in RNSScreenStack (created by ScreenStack)
in ScreenStack (created by NativeStackViewInner)
in NativeStackViewInner (created by NativeStackView)
in RCTView (created by View)
in View (created by SafeAreaInsetsContext)
in SafeAreaProviderCompat (created by NativeStackView)
in NativeStackView (created by NativeStackNavigator)
in PreventRemoveProvider (created by NavigationContent)
in NavigationContent
in Unknown (created by NativeStackNavigator)
in NativeStackNavigator (created by SetupStackScreen)
in SetupStackScreen (created by RootRouter)
in RootRouter (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in Suspense (created by App)
in RCTView (created by View)
in View (created by ModalPanel)
in ModalPanel (created by ApplicationProvider)
in ThemeProvider (created by StyleProvider)
in MappingProvider (created by StyleProvider)
in StyleProvider (created by ApplicationProvider)
in ApplicationProvider (created by App)
in RNCSafeAreaProvider (created by SafeAreaProvider)
in SafeAreaProvider (created by App)
in Provider (created by App)
in App (created by RootApp)
in ReactNativeProfiler (created by RootApp)
in RCTView (created by View)
in View (created by __Sentry.TouchEventBoundary)
in __Sentry.TouchEventBoundary (created by RootApp)
in RootApp
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in MyApp(RootComponent), js engine: hermes
```

**Expected behavior**
I expect the behaviour to be whatever it normally is when a React app is saved while running:
That it just reloads the component and displays the new result.

**Information**
- Day.js Version ^1.11.7
- OS: iOS
- Browser N/A
- Time zone: [e.g. GMT+2 (CET)]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.