-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
fix(runtime-dom): invoker value is actually unknown at runtime #8953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
58491dc
42db610
08d45b0
6e75612
bf95a06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { hyphenate, isArray } from '@vue/shared' | ||
import { hyphenate, isArray, isString, isFunction } from '@vue/shared' | ||
import { | ||
ErrorCodes, | ||
ComponentInternalInstance, | ||
callWithAsyncErrorHandling | ||
callWithAsyncErrorHandling, warn | ||
} from '@vue/runtime-core' | ||
|
||
interface Invoker extends EventListener { | ||
|
@@ -81,7 +81,7 @@ const getNow = () => | |
cachedNow || (p.then(() => (cachedNow = 0)), (cachedNow = Date.now())) | ||
|
||
function createInvoker( | ||
initialValue: EventValue, | ||
initialValue: EventValue | unknown, | ||
instance: ComponentInternalInstance | null | ||
) { | ||
const invoker: Invoker = (e: Event & { _vts?: number }) => { | ||
|
@@ -109,11 +109,22 @@ function createInvoker( | |
[e] | ||
) | ||
} | ||
invoker.value = initialValue | ||
invoker.value = sanitizeEventValue(initialValue) | ||
Tofandel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
invoker.attached = getNow() | ||
return invoker | ||
} | ||
|
||
function sanitizeEventValue(value: unknown): EventValue { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure whether sanitizing the listener is the correct approach. I'm not opposed to adding a warning in dev, but the other parts of this will also impact production builds, and that seems unnecessary for handling a bug that should be fixed during dev. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is if it does happen in prod or otherwise, it's a non recoverable error that kills the Vue component from working further, and it's a runtime error, so not always visible directly, but maybe this could be caught further up as well in the Vue compiler The problem is first and foremost a type issue, we go from an unknown type but mark it in ts as something assumed so it does need to be sanitized in prod as well to ensure no error does happen |
||
if (isFunction(value) || isArray(value)) { | ||
return value as EventValue | ||
} | ||
|
||
if (__DEV__) { | ||
warn('Wrong type passed to the event invoker, did you maybe forget @ or : in front of your prop? Received ' + (isString(value) ? value : typeof value)) | ||
Tofandel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return () => {} | ||
} | ||
|
||
function patchStopImmediatePropagation( | ||
e: Event, | ||
value: EventValue | ||
|
@@ -124,7 +135,7 @@ function patchStopImmediatePropagation( | |
originalStop.call(e) | ||
;(e as any)._stopped = true | ||
} | ||
return value.map(fn => (e: Event) => !(e as any)._stopped && fn && fn(e)) | ||
return (value as Function[]).map(fn => (e: Event) => !(e as any)._stopped && fn && fn(e)) | ||
} else { | ||
return value | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.