From 93ab4553f2c99593ce2c0820f6346514dfc7f4fd Mon Sep 17 00:00:00 2001 From: "jan.kucera" Date: Tue, 18 Jun 2024 12:54:37 +0200 Subject: [PATCH] Adds flag `batchResolveNoTransaction` as a new `PageRendererSettings`. When it is true, transaction is not used in load phase to avoid getting obsolete state from getState. --- .changeset/mighty-ligers-give.md | 6 ++++++ packages/core/src/boot.ts | 1 + .../renderer/AbstractClientPageRenderer.ts | 21 ++++++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 .changeset/mighty-ligers-give.md diff --git a/.changeset/mighty-ligers-give.md b/.changeset/mighty-ligers-give.md new file mode 100644 index 0000000000..a8eab8e90b --- /dev/null +++ b/.changeset/mighty-ligers-give.md @@ -0,0 +1,6 @@ +--- +"@ima/react-page-renderer": minor +"@ima/core": minor +--- + +Adds flag `batchResolveNoTransaction` as a new `PageRendererSettings`. When it is true, transaction is not used in load phase to avoid getting obsolete state from getState. diff --git a/packages/core/src/boot.ts b/packages/core/src/boot.ts index ffcedfd526..81f5c857d8 100644 --- a/packages/core/src/boot.ts +++ b/packages/core/src/boot.ts @@ -121,6 +121,7 @@ export interface AppEnvironment { export interface PageRendererSettings { batchResolve?: boolean; + batchResolveNoTransaction?: boolean; masterElementId: string; documentView: unknown; managedRootView?: unknown; diff --git a/packages/react-page-renderer/src/renderer/AbstractClientPageRenderer.ts b/packages/react-page-renderer/src/renderer/AbstractClientPageRenderer.ts index c57c767ce8..cb5daf2acc 100644 --- a/packages/react-page-renderer/src/renderer/AbstractClientPageRenderer.ts +++ b/packages/react-page-renderer/src/renderer/AbstractClientPageRenderer.ts @@ -311,10 +311,21 @@ export abstract class AbstractClientPageRenderer extends AbstractPageRenderer { } const handler = (resolve: () => void) => () => { - controller.commitStateTransaction(); + if (this._settings?.$Page?.$Render?.batchResolveNoTransaction) { + // TODO IMA@20 - make this default behaviour + this._renderedOnChange = true; + controller.setState(controller.getState()); + } else { + controller.commitStateTransaction(); + } if (!hasResourcesLoaded) { - controller.beginStateTransaction(); + if (this._settings?.$Page?.$Render?.batchResolveNoTransaction) { + this._renderedOnChange = false; + } else { + controller.beginStateTransaction(); + } + setTimeout(() => { requestIdleCallback(handler(resolve), options); }, 75); @@ -323,7 +334,11 @@ export abstract class AbstractClientPageRenderer extends AbstractPageRenderer { } }; - controller.beginStateTransaction(); + if (this._settings?.$Page?.$Render?.batchResolveNoTransaction) { + this._renderedOnChange = false; + } else { + controller.beginStateTransaction(); + } const batchPromise = new Promise(resolve => { setTimeout(() => { requestIdleCallback(handler(resolve), options);