-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(platform/messaging): stop platform in
beforeunload
to avoid pos…
…ting messages to disposed window When posting a message to a disposed window, the browser logs "Failed to execute 'postMessage' on 'DOMWindow'" error. To avoid posting messages to disposed windows, we now disconnect clients already in `beforeunload` instead of `unload`. However, if `beforeunload` is not triggered, e.g., when an iframe is removed, we fall back to `unload`. closes #168
- Loading branch information
1 parent
09b682b
commit 3969c17
Showing
12 changed files
with
217 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...utlet-then-send-message-test-page/clear-outlet-then-send-message-test-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<form autocomplete="off" [formGroup]="form"> | ||
<sci-form-field label="Router Outlet"> | ||
<input [formControlName]="OUTLET" class="e2e-outlet" title="Specifies the name of the outlet which to clear."> | ||
</sci-form-field> | ||
<sci-form-field label="Message Topic"> | ||
<input [formControlName]="TOPIC" class="e2e-topic" title="Specifies the topic where to send a message after cleared the outlet."> | ||
</sci-form-field> | ||
|
||
<button type="submit" class="e2e-run-test" [disabled]="form.invalid" (click)="onRunTestClick()"> | ||
Clear outlet, then send message to topic | ||
</button> | ||
</form> |
10 changes: 10 additions & 0 deletions
10
...utlet-then-send-message-test-page/clear-outlet-then-send-message-test-page.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
:host { | ||
display: grid; | ||
|
||
> form { | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
grid-auto-rows: max-content; | ||
row-gap: .25em; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...-outlet-then-send-message-test-page/clear-outlet-then-send-message-test-page.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2018-2022 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
import {Component} from '@angular/core'; | ||
import {FormControl, FormGroup, ReactiveFormsModule, UntypedFormBuilder, Validators} from '@angular/forms'; | ||
import {MessageClient, OutletRouter} from '@scion/microfrontend-platform'; | ||
import {Beans} from '@scion/toolkit/bean-manager'; | ||
import {SciFormFieldModule} from '@scion/components.internal/form-field'; | ||
|
||
export const OUTLET = 'outlet'; | ||
export const TOPIC = 'topic'; | ||
|
||
@Component({ | ||
selector: 'app-clear-outlet-then-send-message-test-page', | ||
templateUrl: './clear-outlet-then-send-message-test-page.component.html', | ||
styleUrls: ['./clear-outlet-then-send-message-test-page.component.scss'], | ||
standalone: true, | ||
imports: [ReactiveFormsModule, SciFormFieldModule], | ||
}) | ||
export class ClearOutletThenSendMessageTestPageComponent { | ||
|
||
public OUTLET = OUTLET; | ||
public TOPIC = TOPIC; | ||
|
||
public form: FormGroup; | ||
|
||
constructor(formBuilder: UntypedFormBuilder) { | ||
this.form = formBuilder.group({ | ||
[OUTLET]: new FormControl<string>('', Validators.required), | ||
[TOPIC]: new FormControl<string>('', Validators.required), | ||
}); | ||
} | ||
|
||
public async onRunTestClick(): Promise<void> { | ||
// Clear the router outlet. | ||
await Beans.get(OutletRouter).navigate(null, {outlet: this.form.get(OUTLET).value}); | ||
// Send message to the topic. | ||
await Beans.get(MessageClient).publish(this.form.get(TOPIC).value); | ||
// Reset the form. | ||
this.form.reset(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
apps/microfrontend-platform-testing-app/src/app/test-pages/test-pages-routing.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2018-2022 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import {NgModule} from '@angular/core'; | ||
import {RouterModule, Routes} from '@angular/router'; | ||
|
||
const routes: Routes = [ | ||
{ | ||
path: 'clear-outlet-then-send-message-test-page', | ||
data: {pageTitle: 'Test page that clears an outlet and sends a message'}, | ||
loadComponent: (): any => import('./clear-outlet-then-send-message-test-page/clear-outlet-then-send-message-test-page.component').then(m => m.ClearOutletThenSendMessageTestPageComponent), | ||
}, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
exports: [RouterModule], | ||
}) | ||
export class TestPagesRoutingModule { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
.../microfrontend-platform.e2e/src/test-pages/clear-outlet-then-send-message-test-page.po.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2018-2022 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import {FrameLocator, Locator} from '@playwright/test'; | ||
import {OutletPageObject} from '../browser-outlet/browser-outlet.po'; | ||
|
||
export class ClearOutletThenSendMessageTestPagePO implements OutletPageObject { | ||
|
||
public readonly path = 'test-pages/clear-outlet-then-send-message-test-page'; | ||
|
||
private readonly _locator: Locator; | ||
|
||
constructor(frameLocator: FrameLocator) { | ||
this._locator = frameLocator.locator('app-clear-outlet-then-send-message-test-page'); | ||
} | ||
|
||
public async enterOutletName(outlet: string): Promise<void> { | ||
await this._locator.locator('input.e2e-outlet').fill(outlet); | ||
} | ||
|
||
public async enterTopic(topic: string): Promise<void> { | ||
await this._locator.locator('input.e2e-topic').fill(topic); | ||
} | ||
|
||
public async clickRunTest(): Promise<void> { | ||
await this._locator.locator('button.e2e-run-test').click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters