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

#393 - highcharts ssr compatibility angular #394

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions highcharts-angular/src/lib/highcharts-chart.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { OnChanges, OnDestroy } from '@angular/core';
import { Component, ElementRef, EventEmitter, Input, Output, NgZone, SimpleChanges } from '@angular/core';
import { Component, ElementRef, EventEmitter, Input, Output, NgZone, SimpleChanges, PLATFORM_ID, Inject } from '@angular/core';
import type * as Highcharts from 'highcharts';
import type HighchartsESM from 'highcharts/es-modules/masters/highcharts.src';
import { isplatFormServer } from '@angular/common';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { isplatFormServer } from '@angular/common';
import { isPlatformServer } from '@angular/common';


@Component({
selector: 'highcharts-chart',
Expand All @@ -23,10 +24,18 @@ export class HighchartsChartComponent implements OnDestroy, OnChanges {

constructor(
private el: ElementRef,
private _zone: NgZone // #75
private _zone: NgZone, // #75
private @Inject(PLATFORM_ID) platformId: Object,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private @Inject(PLATFORM_ID) platformId: Object,
@Inject(PLATFORM_ID) private platformId: Object

) {}

ssrCompatible() {
if(this.platformId && isplatFormServer(this.platformId)) {
return;
}
}

ngOnChanges(changes: SimpleChanges): void {
this.ssrCompatible();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work. You need to make it like this:

ngOnChanges(changes: SimpleChanges): void {
 if (this.ssrCompatible()) {
      return;
    }
...

See in the demo.

const update = changes.update?.currentValue;
if (changes.options || update) {
this.wrappedUpdateOrCreateChart();
Expand Down Expand Up @@ -62,6 +71,7 @@ export class HighchartsChartComponent implements OnDestroy, OnChanges {
}

ngOnDestroy() { // #44
this.ssrCompatible();
if (this.chart) { // #56
this.chart.destroy();
this.chart = null;
Expand Down