Skip to content

Commit 5f0e606

Browse files
refactoring rendering and lazy loading and performance improvements
1 parent f307c93 commit 5f0e606

File tree

4 files changed

+136
-244
lines changed

4 files changed

+136
-244
lines changed

src/components/App.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ const App = (props: any) => {
1212
// return <ReactiveComponent />;
1313
// return <NonReactiveComponent />;
1414
// return <Test />;
15-
return (
16-
<>
17-
<button
18-
style={{ margin: 10 }}
19-
onClick={() => visible.update((prev) => !prev)}
20-
>
21-
Show/Hide
22-
</button>
23-
{() => (visible.value ? <Test /> : "Hidden")}
24-
</>
25-
);
15+
// return (
16+
// <>
17+
// <button
18+
// style={{ margin: 10 }}
19+
// onClick={() => visible.update((prev) => !prev)}
20+
// >
21+
// Show/Hide
22+
// </button>
23+
// {() => (visible.value ? <Test /> : "Hidden")}
24+
// </>
25+
// );
2626
// return <StylesTest />;
2727
// return <ListsTest />;
28-
// return <PerformanceTest />;
28+
return <PerformanceTest />;
2929
// return <ArrayReturningFC />;
3030
// return <Computed />;
3131
};

src/lazy/Lazyloading.tsx

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ComponentChildren, createSignal, Fiber, PublicSignal } from "../index";
1+
import { ComponentChild, createSignal, PublicSignal } from "../index";
22

33
declare const FRAGMENT = "FRAGMENT";
44

@@ -11,10 +11,8 @@ export function lazy<T extends (props: any) => any>(
1111
importFn: () => Promise<{ default: T }>
1212
): (
1313
props: PropsOf<T> & {
14-
fallback?: ComponentChildren;
15-
errorFallback?:
16-
| ComponentChildren
17-
| ((error: Error) => ComponentChildren);
14+
fallback?: ComponentChild;
15+
errorFallback?: ComponentChild | ((error: Error) => ComponentChild);
1816
}
1917
) => ReturnType<T> {
2018
let Component: T | null = null;
@@ -64,27 +62,6 @@ export function lazy<T extends (props: any) => any>(
6462
const error = createSignal<Error | null>(null);
6563

6664
load(loading, error);
67-
// Validate fallback and errorFallback types
68-
const isValidNode = (val: any) =>
69-
typeof val === "string" ||
70-
(val && typeof val === "object" && "props" in val && "type" in val);
71-
72-
if (props.fallback !== undefined && !isValidNode(props.fallback)) {
73-
throw new Error(
74-
"Invalid fallback: Expected a string or a valid JSX node."
75-
);
76-
}
77-
if (
78-
props.errorFallback !== undefined &&
79-
!(
80-
typeof props.errorFallback === "function" ||
81-
isValidNode(props.errorFallback)
82-
)
83-
) {
84-
throw new Error(
85-
"Invalid errorFallback: Expected a string, a valid JSX node, or a function returning a JSX node."
86-
);
87-
}
8865

8966
return (
9067
<>

0 commit comments

Comments
 (0)