Skip to content

Commit 95ea24a

Browse files
committed
♻️ Refactor Preact JSX handling for improved consistency
Standardize JSX configuration across the project This change improves our Preact integration by: - Removing redundant JSX pragma comments from all UI components - Updating eslint config to ignore 'h' import variable - Simplifying PreactDevEngine to remove unneeded container references - Switching from jsxImportSource to jsxFactory in tsconfig.json - Fixing test cases to align with the new implementation These changes make the codebase more consistent and reduce boilerplate while maintaining the same functionality.
1 parent 366e51d commit 95ea24a

12 files changed

+11
-30
lines changed

eslint.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const eslintConfig = [
4444
"error",
4545
{
4646
argsIgnorePattern: "^_",
47+
varsIgnorePattern: "^h$",
4748
},
4849
],
4950
},

src/common/preact-engine.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export class PreactDevEngine {
2222
private controlValues: ControlValues = {};
2323

2424
// DOM elements
25-
private containerElement: HTMLElement | null = null;
2625
private canvas: HTMLCanvasElement | null = null;
2726
private fpsValue = 0;
2827
private frameCount = 0;
@@ -57,13 +56,10 @@ export class PreactDevEngine {
5756
/**
5857
* Initialize the development environment
5958
*/
60-
public async initialize(container: HTMLElement): Promise<void> {
59+
public async initialize(): Promise<void> {
6160
// Display startup banner
6261
printStartupBanner();
6362

64-
// Store reference to the container but don't overwrite the root element
65-
this.containerElement = container;
66-
6763
// Create canvas reference
6864
this.canvas = document.getElementById("exCanvas") as HTMLCanvasElement;
6965
if (!this.canvas) {

src/dev.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ async function initializeDevEnvironment() {
4343
const engine = new PreactDevEngine();
4444

4545
try {
46-
const container = document.body;
47-
await engine.initialize(container);
46+
await engine.initialize();
4847
console.log("✨ Engine initialized successfully");
4948

5049
// Display welcome notification

src/ui/App.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** @jsx h */
2-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31
import { h, FunctionComponent } from 'preact';
42
import { useState, useEffect } from 'preact/hooks';
53
import { ControlDefinition, ControlValues } from '../common/definitions';

src/ui/ControlsPanel.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** @jsx h */
2-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31
import { h, FunctionComponent } from 'preact';
42
import { ControlDefinition, ControlValues } from '../common/definitions';
53
import { useState, useRef, useEffect } from 'preact/hooks';

src/ui/EffectsPanel.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** @jsx h */
2-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31
import { h, FunctionComponent } from 'preact';
42
import { useEffect, useState } from 'preact/hooks';
53

src/ui/Loader.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** @jsx h */
2-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31
import { h, FunctionComponent } from 'preact';
42

53
interface LoaderProps {

src/ui/Notification.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** @jsx h */
2-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31
import { h, FunctionComponent } from 'preact';
42
import { useEffect, useState } from 'preact/hooks';
53

src/ui/SparklingName.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/** @jsx h */
21
import { h, FunctionComponent } from 'preact';
32
import { useEffect, useState } from 'preact/hooks';
43
import './sparklingName.css';

src/ui/WelcomeModal.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** @jsx h */
2-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31
import { h, FunctionComponent } from 'preact';
42
import { useState } from 'preact/hooks';
53
import { SparklingName } from './SparklingName';

tests/engine.test.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const mockControls = [
8787
// Create mock instance with all required methods
8888
describe("DevEngine", () => {
8989
let engine: any; // Use 'any' type to bypass TypeScript constraints
90-
let container: HTMLElement;
9190

9291
beforeEach(() => {
9392
// Reset mocks
@@ -96,15 +95,14 @@ describe("DevEngine", () => {
9695
// Set up DOM
9796
document.body.innerHTML =
9897
'<div id="container"><canvas id="exCanvas"></canvas></div>';
99-
container = document.getElementById("container") as HTMLElement;
10098

10199
// Create a mock engine with the methods we need
102100
engine = {
103-
initialize: vi.fn().mockImplementation(async (container) => {
101+
initialize: vi.fn().mockImplementation(async () => {
104102
// Create control container
105103
const controlsContainer = document.createElement("div");
106104
controlsContainer.className = "controls-container";
107-
container.appendChild(controlsContainer);
105+
document.getElementById("container")?.appendChild(controlsContainer);
108106

109107
// Call parseControlsFromTemplate directly for the test
110108
parseControlsFromTemplate("<dummy>");
@@ -147,7 +145,7 @@ describe("DevEngine", () => {
147145

148146
// Mock URL params
149147
delete (window as any).location;
150-
window.location = { search: "?effect=simple-wave" } as Location;
148+
(window as any).location = { search: "?effect=simple-wave" };
151149

152150
// Mock fetch with a more complete response
153151
global.fetch = vi
@@ -166,14 +164,14 @@ describe("DevEngine", () => {
166164

167165
describe("initialization", () => {
168166
it("should create control container when initialized", async () => {
169-
await engine.initialize(container);
167+
await engine.initialize();
170168
const controlsContainer = document.querySelector(".controls-container");
171169
expect(controlsContainer).not.toBeNull();
172170
});
173171

174172
it("should create effect selector when multiple effects exist", async () => {
175173
// We already have multiple effects in the mocked effects array
176-
await engine.initialize(container);
174+
await engine.initialize();
177175

178176
// Check if effect was loaded properly
179177
expect(parseControlsFromTemplate).toHaveBeenCalled();
@@ -191,7 +189,7 @@ describe("DevEngine", () => {
191189
template: "./effects/simple-wave/template.html",
192190
});
193191

194-
await engine.initialize(container);
192+
await engine.initialize();
195193

196194
// Verify the effect is loaded
197195
expect(generateControlUI).toHaveBeenCalled();

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"noUncheckedSideEffectImports": true,
2222

2323
/* JSX for Preact */
24-
"jsx": "react-jsx",
25-
"jsxImportSource": "preact",
24+
"jsx": "react",
25+
"jsxFactory": "h",
2626

2727
/* GLSL shader imports */
2828
"types": [

0 commit comments

Comments
 (0)