Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds flag batchResolveNoTransaction as a new PageRendererSettings #570

Merged
merged 1 commit into from
Jun 18, 2024
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: 6 additions & 0 deletions .changeset/mighty-ligers-give.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions packages/core/src/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export interface AppEnvironment {

export interface PageRendererSettings {
batchResolve?: boolean;
batchResolveNoTransaction?: boolean;
masterElementId: string;
documentView: unknown;
managedRootView?: unknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<void>(resolve => {
setTimeout(() => {
requestIdleCallback(handler(resolve), options);
Expand Down
Loading