Skip to content

Commit 47a771c

Browse files
committed
Don't dynamically create the static logo
1 parent 8b4ba03 commit 47a771c

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/app/index.module.css

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
transform: translateY(-50%);
4343
}
4444

45+
.hidden {
46+
display: none;
47+
}
48+
4549
.title {
4650
text-align: center;
4751
margin-bottom: calc(var(--mantine-spacing-xl));

src/components/logo.tsx

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import React from "react";
4+
import Image from "next/image";
45
import Script from "next/script";
56
import classes from "../app/index.module.css";
67

@@ -36,17 +37,6 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
3637
this.container = React.createRef();
3738
}
3839

39-
private createStaticLogo() {
40-
if (this.container.current) {
41-
const staticLogo = document.createElement("IMG") as HTMLImageElement;
42-
staticLogo.src = "/logo.svg";
43-
staticLogo.alt = "Ruffle Logo";
44-
staticLogo.className = classes.staticLogo;
45-
this.container.current.textContent = "";
46-
this.container.current.appendChild(staticLogo);
47-
}
48-
}
49-
5040
private load() {
5141
if (this.player) {
5242
// Already loaded.
@@ -57,7 +47,6 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
5747

5848
if (this.player) {
5949
this.container.current!.appendChild(this.player);
60-
6150
this.player.load({
6251
url: "/logo-anim.swf",
6352
autoplay: "on",
@@ -66,16 +55,21 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
6655
contextMenu: "off",
6756
splashScreen: false,
6857
preferredRenderer: "canvas",
58+
}).then(() => {
59+
this?.container?.current?.querySelector("img")?.classList?.toggle(classes.hidden);
6960
}).catch(() => {
70-
this.createStaticLogo();
61+
this.player?.remove();
62+
this.player = null;
7163
});
7264
this.player.style.width = "100%";
7365
this.player.style.height = "100%";
74-
} else {
75-
this.createStaticLogo();
7666
}
7767
}
7868

69+
componentDidMount() {
70+
this.load();
71+
}
72+
7973
componentWillUnmount() {
8074
this.player?.remove();
8175
this.player = null;
@@ -87,9 +81,10 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
8781
<Script
8882
src="https://unpkg.com/@ruffle-rs/ruffle"
8983
onReady={() => this.load()}
90-
onError={() => this.createStaticLogo()}
9184
/>
92-
<div ref={this.container} className={this.props.className} />
85+
<div ref={this.container} className={this.props.className}>
86+
<Image src="/logo.svg" alt="Ruffle Logo" className={classes.staticLogo} width="340" height="110" />
87+
</div>
9388
</>
9489
);
9590
}

0 commit comments

Comments
 (0)