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

Angular: Fix some Ivy rendering glitches #15279

Merged
merged 2 commits into from
Jun 17, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export abstract class AbstractRenderer {
return new Promise<void>((resolve) => {
if (platformRef && !platformRef.destroyed) {
platformRef.onDestroy(async () => {
await AbstractRenderer.resetCompiledComponents();
resolve();
});
// Destroys the current Angular platform and all Angular applications on the page.
Expand Down Expand Up @@ -83,6 +82,8 @@ export abstract class AbstractRenderer {

protected abstract beforeFullRender(): Promise<void>;

protected abstract afterFullRender(): Promise<void>;

/**
* Bootstrap main angular module with main component or send only new `props` with storyProps$
*
Expand Down Expand Up @@ -136,6 +137,7 @@ export abstract class AbstractRenderer {
createStorybookModule(moduleMetadata),
parameters.bootstrapModuleOptions ?? undefined
);
await this.afterFullRender();
}

protected initAngularRootElement(targetDOMNode: HTMLElement, targetSelector: string) {
Expand Down
4 changes: 4 additions & 0 deletions app/angular/src/client/preview/angular-beta/CanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ export class CanvasRenderer extends AbstractRenderer {
async beforeFullRender(): Promise<void> {
await CanvasRenderer.resetPlatformBrowserDynamic();
}

async afterFullRender(): Promise<void> {
await AbstractRenderer.resetCompiledComponents();
}
}
15 changes: 13 additions & 2 deletions app/angular/src/client/preview/angular-beta/DocsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ export class DocsRenderer extends AbstractRenderer {
await DocsRenderer.resetPlatformBrowserDynamic();
});

await super.render({ ...options, forced: false });
/**
* Destroy and recreate the PlatformBrowserDynamic of angular
* when doc re render. Allows to call ngOnDestroy of angular
* for previous component
*/
channel.once(Events.DOCS_RENDERED, async () => {
kroeder marked this conversation as resolved.
Show resolved Hide resolved
await DocsRenderer.resetPlatformBrowserDynamic();
});

await AbstractRenderer.resetCompiledComponents();
await super.render({ ...options, forced: false });
}

async beforeFullRender(): Promise<void> {}

async afterFullRender(): Promise<void> {
await AbstractRenderer.resetCompiledComponents();
}
}