Skip to content

Explicitly throw an error when overlay-kit cannot be used #178

@ono-eth

Description

@ono-eth

Description

In useClientLayoutEffect, we currently exit silently if neither a browser nor a React Native environment is detected:

function useClientLayoutEffect(...args: Parameters<typeof useLayoutEffect>) {
  const isBrowser = typeof document !== 'undefined';
  const isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';

  if (!isBrowser && !isReactNative) return;

  useLayoutEffect(...args);
}

In a React Native + Jest testing setup, Jest runs in a pure Node environment (no document, no navigator.product === 'ReactNative'), so this hook simply returns without running the effect or cleanup. As a result, emitter handlers never register or unregister, and tests fail silently.

Environment

ReactNative + jest (Node)

Observed Behavior

The hook exits early, so emitter.on and emitter.off never run, and no warning or error is thrown.

Expected Behavior

The developer should be informed that the environment is unsupported—either by throwing an error or logging a warning—so that tests don’t fail silently.

Follow-up Action & Documentation Update

Add a note to the “Test Environment Setup” section of the README or docs to ensure hooks work under React Native + Jest.

// jest.setup.js
global.navigator = { product: 'ReactNative' };

This ensures that useClientLayoutEffect detects the React Native environment during testing.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions