Commit 8208e4c
committed
Only auto-load a file field when the ref is a genuinely loaded img (#267)
`useCwaFile`'s mount-time "already loaded" shortcut read:
if (ops.imageRef.value?.complete || ops.imageRef.value?.naturalHeight !== 0)
The ref is not always a bare <img>. `ref="file"` on a COMPONENT — as the
playground's Image.vue does with <NuxtImg ref="file"> — resolves to the
component instance, not the element. A ref name that doesn't match
`fileProp` resolves to null. And a file field needn't be an image at all.
In every one of those cases `naturalHeight` is `undefined`, and
`undefined !== 0` is TRUE, so `handleLoad()` fired on mount and `loaded`
was true from the start — defeating the whole load-detection mechanism.
Visibly, the placeholder vanished instantly and the image popped in
unfaded, because nothing was waiting for @load.
Unwrap a component instance to its root element, and only apply the
heuristic to something that can actually report img load state. Anything
else waits for @load, which still fires normally.
This is section 3 of #267. The `Cannot redefine property` crash and the
implicit-useTemplateRef design question are separate and remain open.
The existing `complete || naturalHeight !== 0` heuristic is deliberately
left as-is rather than re-litigated here — the fix is scoped to what the
ref resolves to, not to how a loaded img is recognised.1 parent 698e89f commit 8208e4c
2 files changed
Lines changed: 52 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
140 | 178 | | |
141 | 179 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
63 | 69 | | |
64 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
65 | 78 | | |
66 | 79 | | |
67 | 80 | | |
| |||
0 commit comments