Skip to content

Commit db731d4

Browse files
bunin-avAleksandr Bunin
andauthored
Issue-1075 v-image ssr bug (#1076)
* fix bug * imp doc * up --------- Co-authored-by: Aleksandr Bunin <[email protected]>
1 parent 9dfa85e commit db731d4

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Changelog
1111
1212
_Note: Gaps between patch versions are faulty, broken or test releases._
1313

14+
## v4.0.0-beta.47 (2024-01-16)
15+
16+
#### :bug: Bug Fix
17+
18+
* Fixed incorrect image state during hydration `components/directives/image`
19+
1420
## v4.0.0-beta.46 (2024-01-11)
1521

1622
#### :bug: Bug Fix

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"packageManager": "[email protected]",
77
"typings": "index.d.ts",
88
"license": "MIT",
9-
"version": "4.0.0-beta.46",
9+
"version": "4.0.0-beta.47",
1010
"author": {
1111
"name": "kobezzza",
1212
"email": "[email protected]",

src/components/directives/image/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Changelog
99
> - :house: [Internal]
1010
> - :nail_care: [Polish]
1111
12+
## v4.?.? (2024-01-??)
13+
14+
#### :bug: Bug Fix
15+
16+
* Fixed incorrect image state during hydration
17+
1218
## v4.0.0-alpha.1 (2022-12-14)
1319

1420
#### :boom: Breaking Change

src/components/directives/image/helpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export function createImgElement(
6969
onerror(e: Event) {
7070
const img = (<HTMLImageElement>e.target);
7171
img.setAttribute('data-img', 'failed');
72-
img.style.opacity = '0';
7372
},
7473

7574
style: {

src/components/directives/image/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,27 @@ function mounted(el: HTMLElement, params: DirectiveParams, vnode: VNode): void {
138138
break;
139139

140140
default:
141+
handleDefaultCase();
142+
}
143+
144+
function handleDefaultCase() {
145+
if (img == null) {
146+
return;
147+
}
148+
149+
if (!img.complete) {
141150
$a.once(img, 'load', onLoad, group);
142151
$a.once(img, 'error', onError, group);
152+
153+
return;
154+
}
155+
156+
if (img.naturalWidth > 0) {
157+
void onLoad();
158+
159+
} else {
160+
onError();
161+
}
143162
}
144163

145164
async function onLoad() {
@@ -152,7 +171,6 @@ function mounted(el: HTMLElement, params: DirectiveParams, vnode: VNode): void {
152171
try {
153172
await $a.sleep(50, group);
154173

155-
// eslint-disable-next-line require-atomic-updates
156174
img.style.opacity = '1';
157175

158176
el.style['background-image'] = '';
@@ -172,6 +190,8 @@ function mounted(el: HTMLElement, params: DirectiveParams, vnode: VNode): void {
172190
return;
173191
}
174192

193+
img.style.opacity = '0';
194+
175195
el.style['background-image'] = el.getAttribute('data-broken-image') ?? '';
176196
el.setAttribute('data-image', 'broken');
177197

0 commit comments

Comments
 (0)