Skip to content

Commit

Permalink
fix: LazyActivityComponent._stackflow.load() -> LazyActivityComponent…
Browse files Browse the repository at this point in the history
…._load()
  • Loading branch information
tonyfromundefined committed Jan 15, 2025
1 parent 0a20f4f commit 108b022
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ import type { StaticActivityComponentType } from "./StaticActivityComponentType"

export type LazyActivityComponentType<T extends { [K in keyof T]: any } = {}> =
React.LazyExoticComponent<StaticActivityComponentType<T>> & {
_stackflow?: {
type: "lazy";
load: () => Promise<{ default: StaticActivityComponentType<T> }>;
};
_load?: () => Promise<{ default: StaticActivityComponentType<T> }>;
};
2 changes: 1 addition & 1 deletion integrations/react/src/future/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function lazy<T extends { [K in keyof T]: any } = {}>(
};

const LazyComponent: LazyActivityComponentType<T> = React.lazy(cachedLoad);
LazyComponent._stackflow = { type: "lazy", load: cachedLoad };
LazyComponent._load = cachedLoad;

return LazyComponent;
}
26 changes: 7 additions & 19 deletions integrations/react/src/future/loader/loaderPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ export function loaderPlugin<
config: input.config,
});

if (
loaderData instanceof Promise ||
"_stackflow" in matchActivityComponent
) {
if (loaderData instanceof Promise || "_load" in matchActivityComponent) {
pause();
}

Expand All @@ -92,11 +89,8 @@ export function loaderPlugin<
if (loaderData instanceof Promise) {
promises.push(loaderData);
}
if (
"_stackflow" in matchActivityComponent &&
matchActivityComponent._stackflow?.type === "lazy"
) {
promises.push(matchActivityComponent._stackflow.load());
if ("_load" in matchActivityComponent && matchActivityComponent._load) {
promises.push(matchActivityComponent._load());
}

Promise.all(promises).finally(() => {
Expand All @@ -113,7 +107,7 @@ export function loaderPlugin<
},
onBeforeReplace({
actionParams,
actions: { overrideActionParams, dispatchEvent, pause, resume },
actions: { overrideActionParams, pause, resume },
}) {
const { activityName, activityParams, activityContext } = actionParams;

Expand All @@ -134,10 +128,7 @@ export function loaderPlugin<
config: input.config,
});

if (
loaderData instanceof Promise ||
"_stackflow" in matchActivityComponent
) {
if (loaderData instanceof Promise || "_load" in matchActivityComponent) {
pause();
}

Expand All @@ -146,11 +137,8 @@ export function loaderPlugin<
if (loaderData instanceof Promise) {
promises.push(loaderData);
}
if (
"_stackflow" in matchActivityComponent &&
matchActivityComponent._stackflow?.type === "lazy"
) {
promises.push(matchActivityComponent._stackflow.load());
if ("_load" in matchActivityComponent && matchActivityComponent._load) {
promises.push(matchActivityComponent._load());
}

Promise.all(promises).finally(() => {
Expand Down

0 comments on commit 108b022

Please sign in to comment.