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

fix(kit): File throws SSR error ReferenceError: File is not defined #7085

Merged
merged 2 commits into from
Mar 26, 2024
Merged
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
10 changes: 8 additions & 2 deletions projects/kit/components/files/file/file.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@angular/core';
import type {SafeValue} from '@angular/platform-browser';
import {DomSanitizer} from '@angular/platform-browser';
import {WINDOW} from '@ng-web-apis/common';
import type {TuiContext} from '@taiga-ui/cdk';
import {tuiIsObserved, tuiPure} from '@taiga-ui/cdk';
import type {TuiSizeL} from '@taiga-ui/core';
Expand Down Expand Up @@ -51,6 +52,7 @@ export class TuiFileComponent {
private readonly sanitizer = inject(DomSanitizer);
private readonly options = inject(TUI_FILE_OPTIONS);
private readonly units$ = inject(TUI_DIGITAL_INFORMATION_UNITS);
private readonly win = inject(WINDOW) as Window & {File: typeof File};

@Input()
public file: TuiFileLike = {name: ''};
Expand Down Expand Up @@ -146,8 +148,12 @@ export class TuiFileComponent {
return file.src;
}

// TODO: iframe warning
if (file instanceof File && file.type && file.type.startsWith('image/')) {
if (
this.win.File &&
file instanceof this.win.File &&
file.type &&
file.type.startsWith('image/')
) {
return this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(file));
}

Expand Down
Loading