Skip to content

Commit edb331b

Browse files
fix: Linting hanging due to missing images (#1988)
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
1 parent 5c6557d commit edb331b

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

.changeset/sour-deers-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-email": patch
3+
---
4+
5+
fix linting hanging because of missing images
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promises as fs } from 'node:fs';
1+
import { promises as fs, existsSync } from 'node:fs';
22
/* eslint-disable @typescript-eslint/no-non-null-assertion */
33
import type http from 'node:http';
44
import path from 'node:path';
@@ -16,25 +16,29 @@ export const serveStaticFile = async (
1616

1717
const fileAbsolutePath = path.join(staticBaseDir, pathname);
1818

19-
const fileHandle = await fs.open(fileAbsolutePath, 'r');
20-
2119
try {
20+
const fileHandle = await fs.open(fileAbsolutePath, 'r');
2221
const fileData = await fs.readFile(fileHandle);
2322

2423
// if the file is found, set Content-type and send data
2524
res.setHeader('Content-type', lookup(ext) || 'text/plain');
2625
res.end(fileData);
27-
} catch (exception) {
28-
console.error(
29-
`Could not read file at ${fileAbsolutePath} to be served, here's the exception:`,
30-
exception,
31-
);
3226

33-
res.statusCode = 500;
34-
res.end(
35-
'Could not read file to be served! Check your terminal for more information.',
36-
);
37-
} finally {
3827
fileHandle.close();
28+
} catch (exception) {
29+
if (!existsSync(fileAbsolutePath)) {
30+
res.statusCode = 404;
31+
res.end();
32+
} else {
33+
console.error(
34+
`Could not read file at ${fileAbsolutePath} to be served, here's the exception:`,
35+
exception,
36+
);
37+
38+
res.statusCode = 500;
39+
res.end(
40+
'Could not read file to be served! Check your terminal for more information.',
41+
);
42+
}
3943
}
4044
};

packages/react-email/src/components/toolbar/use-cached-state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ export const useCachedState = <T>(key: string) => {
44
let value: T | undefined = undefined;
55
if ('localStorage' in global) {
66
const storedValue = global.localStorage.getItem(key);
7-
if (storedValue !== null) {
7+
if (storedValue !== null && storedValue !== 'undefined') {
88
try {
99
value = JSON.parse(storedValue) as T;
1010
} catch (exception) {
1111
console.warn(
1212
'Failed to load stored value for',
1313
key,
1414
'with value',
15-
value,
15+
storedValue,
1616
);
1717
}
1818
}

0 commit comments

Comments
 (0)