Skip to content

Commit

Permalink
Implemented remote root render for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
js-goupil committed Sep 19, 2024
1 parent 547404d commit dccb7f8
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions packages/ui-extensions-react/src/surfaces/admin/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from '@shopify/ui-extensions/admin';

import {ExtensionApiContext} from './context';
import {remoteRootRender} from '../../utilities/remoteRootRender';

/**
* Registers your React-based UI Extension to run for the selected extension point.
Expand Down Expand Up @@ -36,24 +37,12 @@ export function reactExtension<ExtensionTarget extends RenderExtensionTarget>(
return extension<'Playground'>(target as any, async (root, api) => {
const element = await render(api as ApiForRenderExtension<ExtensionTarget>);

await new Promise<void>((resolve, reject) => {
try {
remoteRender(
<ExtensionApiContext.Provider value={api}>
{element}
</ExtensionApiContext.Provider>,
root,
() => {
resolve();
},
);
} catch (error) {
// Workaround for https://github.com/Shopify/ui-extensions/issues/325
// eslint-disable-next-line no-console
console.error(error);
reject(error);
}
});
return remoteRootRender(
<ExtensionApiContext.Provider value={api}>
{element}
</ExtensionApiContext.Provider>,
root,
);
}) as any;
}

Expand Down

0 comments on commit dccb7f8

Please sign in to comment.