Skip to content

Commit

Permalink
Avoid accessing globals at module initialization time. (#129)
Browse files Browse the repository at this point in the history
* Avoid accessing global at module initialization time.
  
  This to allow creation of a snapshot-able bundle in certain JS environments.

---------

Co-authored-by: Mayur Arora <[email protected]>
  • Loading branch information
mayurarora0903 and Mayur Arora authored Aug 23, 2024
1 parent 83446e7 commit c1ee4f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-dingos-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-loosely-lazy": patch
---

Avoid accessing global at module initialization time.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { ProfilerContext } from '../../profiler';
import type { Status } from './types';
import { useSubscription } from './utils';

const { requestIdleCallback = setTimeout } = window;

export function createComponentClient<C extends ComponentType<any>>({
defer,
deferred,
Expand All @@ -31,6 +29,7 @@ export function createComponentClient<C extends ComponentType<any>>({
dataLazyId: string;
moduleId: string;
}) {
const { requestIdleCallback = setTimeout } = window;
const ResolvedLazy = lazy(() => deferred.promise);

return (props: ComponentProps<C>) => {
Expand Down

0 comments on commit c1ee4f7

Please sign in to comment.