mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
React: Force act running always in sequence
This commit is contained in:
parent
de65bec511
commit
cc60f03f38
@ -45,6 +45,23 @@ class ErrorBoundary extends ReactComponent<{
|
|||||||
|
|
||||||
const Wrapper = FRAMEWORK_OPTIONS?.strictMode ? StrictMode : Fragment;
|
const Wrapper = FRAMEWORK_OPTIONS?.strictMode ? StrictMode : Fragment;
|
||||||
|
|
||||||
|
const actQueue: (() => Promise<void>)[] = [];
|
||||||
|
let isActing = false;
|
||||||
|
|
||||||
|
const processActQueue = async () => {
|
||||||
|
if (isActing || actQueue.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isActing = true;
|
||||||
|
const actTask = actQueue.shift();
|
||||||
|
if (actTask) {
|
||||||
|
await actTask();
|
||||||
|
}
|
||||||
|
isActing = false;
|
||||||
|
processActQueue();
|
||||||
|
};
|
||||||
|
|
||||||
export async function renderToCanvas(
|
export async function renderToCanvas(
|
||||||
{
|
{
|
||||||
storyContext,
|
storyContext,
|
||||||
@ -81,12 +98,22 @@ export async function renderToCanvas(
|
|||||||
unmountElement(canvasElement);
|
unmountElement(canvasElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
await act(async () => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
await renderElement(element, canvasElement, storyContext?.parameters?.react?.rootOptions);
|
try {
|
||||||
|
actQueue.push(async () => {
|
||||||
|
await act(async () => {
|
||||||
|
await renderElement(element, canvasElement, storyContext?.parameters?.react?.rootOptions);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
processActQueue();
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return async () => {
|
return () => {
|
||||||
await act(() => {
|
act(() => {
|
||||||
unmountElement(canvasElement);
|
unmountElement(canvasElement);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user