Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions airflow-core/src/airflow/ui/src/pages/ExternalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { Box } from "@chakra-ui/react";
import { useTranslation } from "react-i18next";
import { useParams } from "react-router-dom";
import { useLocation, useParams } from "react-router-dom";

import { usePluginServiceGetPlugins } from "openapi/queries";
import { ProgressBar } from "src/components/ui";
Expand All @@ -32,6 +32,8 @@ export const ExternalView = () => {
const { page } = useParams();
const { data: pluginData, isLoading } = usePluginServiceGetPlugins();

const { pathname } = useLocation();

const externalView =
page === "legacy-fab-views"
? {
Expand Down Expand Up @@ -82,7 +84,7 @@ export const ExternalView = () => {
m={-2} // Compensate for parent padding
minHeight={0}
>
<ReactPlugin reactApp={reactApp} />
<ReactPlugin key={pathname} reactApp={reactApp} />
</Box>
);
}
Expand Down
20 changes: 15 additions & 5 deletions airflow-core/src/airflow/ui/src/pages/ReactPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,29 @@ const loadPlugin = (reactApp: ReactAppResponse): Promise<{ default: PluginCompon
// eslint-disable-next-line no-console
console.error("Component failed to load:", error);

return {
default: ErrorPage,
};
return { default: ErrorPage };
});

export const ReactPlugin = ({ reactApp }: { readonly reactApp: ReactAppResponse }) => {
const { dagId, mapIndex, runId, taskId } = useParams();

const Plugin = lazy(() => loadPlugin(reactApp));
// If the plugin component was already registered on the global object by a previous load,
// render it directly without going through Suspense/lazy (avoids flashing the spinner).
const existing = (globalThis as Record<string, unknown>)[reactApp.name];

if (typeof existing === "function") {
const Plugin = existing as PluginComponentType;

return <Plugin dagId={dagId} mapIndex={mapIndex} runId={runId} taskId={taskId} />;
}

// Otherwise, lazy-load the bundle once. When it resolves, it must set a function component
// under globalThis[reactApp.name], which we then use as the default export.
const LazyPlugin = lazy(() => loadPlugin(reactApp));

return (
<Suspense fallback={<Spinner />}>
<Plugin dagId={dagId} mapIndex={mapIndex} runId={runId} taskId={taskId} />
<LazyPlugin dagId={dagId} mapIndex={mapIndex} runId={runId} taskId={taskId} />
</Suspense>
);
};
Loading