Skip to content

Commit

Permalink
Ensure we unwrap custom .then() (#4547)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Nov 9, 2024
1 parent aee8285 commit 76d6d4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compat/src/suspense.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Component, ComponentChild, ComponentChildren } from '../../src';
//
// Suspense/lazy
// -----------------------------------
export function lazy<T>(loader: () => Promise<{ default: T } | T>): T;
export function lazy<T>(
loader: () => Promise<{ default: T } | T>
): T extends { default: infer U } ? U : T;

export interface SuspenseProps {
children?: ComponentChildren;
Expand Down
15 changes: 15 additions & 0 deletions compat/test/ts/suspense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,18 @@ function ReactSuspenseListTester(_props: any) {
</React.SuspenseList>
);
}

const Comp = () => <p>Hello world</p>;

const importComponent = async () => {
return { MyComponent: Comp };
};

const Lazy = React.lazy(() =>
importComponent().then(mod => ({ default: mod.MyComponent }))
);

// eslint-disable-next-line
function App() {
return <Lazy />;
}

0 comments on commit 76d6d4d

Please sign in to comment.