[英]Angular App gets freeze when navigating one view to another with high payload response of HTTP Request
I have an angular 9.1.11 application that is gets freezed after navigating from navigating from one page to another page (different module with lazy loading).我有一个 angular 9.1.11 应用程序在从一个页面导航到另一个页面后被冻结(具有延迟加载的不同模块)。
My scenario is like:我的场景是这样的:
I have an action button View Report
that navigates to different route say /reportData
with query params appended /reportData?reportId=XYZ&reportDate=YZX
.我有一个操作按钮
View Report
,它导航到不同的路线,例如/reportData
并附加了查询参数/reportData?reportId=XYZ&reportDate=YZX
。
In my ReportComponent, I'm taking the queryParams from ActivatedRoute
and using the params I'm calling a HTTP request在我的 ReportComponent 中,我从
ActivatedRoute
获取 queryParams 并使用我正在调用 HTTP 请求的参数
the Request will respond with heavy payload with 4-5 mb
minimum as response.请求将以
4-5 mb
的最小负载响应作为响应。
When I click the View Report
the page freeze, after few seconds it redirecting to /reportData?reportId=XYZ&reportDate=YZX
and after that HTTP call gets hit.当我单击
View Report
时,页面冻结,几秒钟后它重定向到/reportData?reportId=XYZ&reportDate=YZX
,然后 HTTP 调用被击中。
Additional information:附加信息:
viewReport: 0.004150390625ms Start --> from page One
viewReport: 186.335205078125ms Report - OnInit --> Freezed
viewReport: 17733.464111328125ms Report - After ViewInit
viewReport: 17754.35009765625ms - viewReport fetchHttp Inital --> HttpRequest with upto 4-5 mb response
viewReport: 23164.468994140625ms Report - viewReport fetchHttp subscribed
viewReport: 23188.69091796875ms Report - fetchHttp subscribed End
viewReport: 23188.951904296875ms End
The component that presents the problem is the following:出现问题的组件如下:
Page One:第一页:
viewReport(reportForm: FormArray | FormGroup) {
console.time("viewReport");
console.timeLog("viewReport", "Start");
const queryParams: Params = {
reportId: reportForm.get("reportUuid").value,
reportDate: reportForm.get("reportDate").value
};
this.router.navigate(["/reportData"], {
queryParams,
queryParamsHandling: "merge" // remove to replace all query params by provided
});
}
Report Component:报告组件:
@Component({
selector: "kt-report-view",
templateUrl: "./report-view.component.html",
styleUrls: ["./report-view.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [ReportService]
})
export class ReportViewComponent implements OnInit, OnDestroy, AfterViewInit {
reportData: string;
reportLoader$: BehaviorSubject<boolean> = new BehaviorSubject(false);
private reportId: string;
private reportDate: any
constructor(
private router: Router,
private reportService: ReportService,
private activatedRouter: ActivatedRoute
) {}
ngOnInit() {
console.timeLog("viewReport", "Report - OnInit"); // Freezes Here
const bodyName = document.getElementsByTagName("body")[0];
bodyName.classList.add("bg-white");
}
ngAfterViewInit(): void {
console.timeLog("viewReport", "Report - After ViewInit");
this.activatedRouter.queryParams.subscribe(
(res: { reportId: string; reportDate: any }) => {
if (res) {
this.reportId = res.reportId;
this.reportDate = res.reportDate;
this.fetchReportData(); // calling HTTP Request
}
}
);
}
ngOnDestroy(): void {
const bodyName = document.getElementsByTagName("body")[0];
if (bodyName.classList.contains("bg-white")) {
bodyName.classList.remove("bg-white");
}
}
fetchReportData() {
console.timeLog("viewReport", "Report - viewReport fetchHttp Inital");
this.reportLoader$.next(true);
this.reportService.getReportData(this.reportId, this.reportDate).subscribe(
async (report: any) => {
console.timeLog("viewReport", "Report - viewReport fetchHttp subscribed Inital");
const data: any = await this.constructOverAllHtml(report);
console.timeLog("viewReport", "Report - fetchHttp subscribed End");
this.reportData = data;
this.reportLoader$.next(false);
console.timeEnd("viewReport");
},
(err) => {
this.reportLoader$.next(false);
console.log(err);
}
);
}
private constructOverAllHtml(report: any): Promise<any> {
return new Promise((resolve, reject) => {
let finalContent: string = "";
const mainReportHTML = report.mainReport.reportHTML;
finalContent = mainReportHTML;
if (report.childReport)
report.childReport.map((reportData: any, index: number) => {
finalContent += ` <p> </p><p><strong>Child Report:
${index + 1}</strong></p> ${reportData.reportHTML}`;
});
resolve(finalContent);
});
}
} }
why are you dragging data with route params that too of such huge amount.您为什么要使用如此庞大的路由参数来拖动数据。 even if it's to a single route or taking between multiple routes, pass very fewer data with route params or query string,.
即使是单条路线或在多条路线之间使用,使用路由参数或查询字符串传递的数据也非常少。 of say, simple string, small object or small array.
例如,简单的字符串、小 object 或小数组。
My Suggestion would be我的建议是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.