Skip to content

Commit 8b92dc3

Browse files
committed
Fix some page load issues
1 parent 0b8a493 commit 8b92dc3

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/LazyImage.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import cn from "classnames";
33
import { Component, ComponentProps, JSX } from "solid-js";
44
import { breakpoint, withStyle } from "~/style/commonStyle";
55

6-
const isImageCached = (url: string) => {
7-
const img = new Image();
8-
img.src = url;
9-
return img.complete;
10-
};
11-
126
interface Props extends ComponentProps<"img"> {
137
style?: JSX.CSSProperties;
148
class?: string;
@@ -24,12 +18,13 @@ export interface LazyImageMeta {
2418
const LazyImage: (meta: LazyImageMeta) => Component<Props> =
2519
(meta) => (props) => {
2620
const { class: $class, style, ...rest } = $destructure(props);
21+
let imageRef!: HTMLImageElement;
2722
let hasJS = $signal(false);
2823
let loaded = $signal(false);
2924

3025
$effect(() => {
3126
hasJS = true;
32-
loaded = isImageCached(meta.url);
27+
loaded ||= imageRef.complete;
3328
});
3429

3530
return (
@@ -43,11 +38,10 @@ const LazyImage: (meta: LazyImageMeta) => Component<Props> =
4338
"--color2": meta.gradient[0],
4439
}}>
4540
<img
41+
ref={imageRef}
4642
class={cn({ hasJS, loaded })}
43+
onLoad={() => { loaded = true; }}
4744
src={meta.url}
48-
onload={() => {
49-
loaded = true;
50-
}}
5145
{...rest}
5246
/>
5347
</div>
@@ -76,11 +70,11 @@ const _LazyImage = css`
7670
height: 100%;
7771
object-fit: inherit;
7872
// hide text when loading image
79-
text-indent: 100%;
73+
font-size: 0;
8074
8175
@supports (animation-name: fadeIn) {
8276
opacity: 0;
83-
animation: fadeIn 200ms 4s forwards;
77+
animation: fadeIn 200ms 1s forwards;
8478
}
8579
@keyframes fadeIn {
8680
0% {

src/app.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Header from "~/Header";
99
import { config } from "~/config";
1010
import { routes } from "~/routes";
1111
import { lazy } from "solid-lazy-plus";
12+
import { css } from "@linaria/core";
13+
import { style } from "~/style/styleUtilTS";
1214

1315
const Preload = lazy(() => import("./preload"));
1416

@@ -20,6 +22,7 @@ export default function App() {
2022
root={(props) => {
2123
return (
2224
<>
25+
{/* <style innerText={headCSS}/> */}
2326
<Title>Blog of a programming rabbit</Title>
2427
<Meta
2528
name="description"
@@ -42,3 +45,7 @@ export default function App() {
4245
</MetaProvider>
4346
);
4447
}
48+
49+
const headCSS = style`
50+
body > * { visibility: hidden; }
51+
`;

src/style/global.style.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export const globals = css`
6161
text-rendering: optimizeLegibility;
6262
6363
${text("primary", "body", "colors/text-600a")}
64+
65+
// > * { visibility: initial !important; }
6466
}
6567
6668
em {

0 commit comments

Comments
 (0)