Skip to content

Commit

Permalink
feat: patch
Browse files Browse the repository at this point in the history
  • Loading branch information
zhennann committed Jan 6, 2025
1 parent e8e8422 commit 221a8d3
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/compiler-sfc/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@vue/compiler-sfc",
"name": "@cabloy/vue-compiler-sfc",
"version": "3.5.13",
"description": "@vue/compiler-sfc",
"main": "dist/compiler-sfc.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ function importSourceToScope(

function resolveExt(filename: string, fs: FS) {
// #8339 ts may import .js but we should resolve to corresponding ts or d.ts
filename = filename.replace(/\.js$/, '')
filename = filename.replace(/\.jsx?$/, '')
const tryResolve = (filename: string) => {
if (fs.fileExists(filename)) return filename
}
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@vue/reactivity",
"name": "@cabloy/vue-reactivity",
"version": "3.5.13",
"description": "@vue/reactivity",
"main": "index.js",
Expand Down
6 changes: 5 additions & 1 deletion packages/reactivity/src/baseHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class BaseReactiveHandler implements ProxyHandler<Target> {

if (isRef(res)) {
// ref unwrapping - skip unwrap for Array + integer key.
return targetIsArray && isIntegerKey(key) ? res : res.value
return targetIsArray && isIntegerKey(key) ? res : unrefNested(res)
}

if (isObject(res)) {
Expand All @@ -133,6 +133,10 @@ class BaseReactiveHandler implements ProxyHandler<Target> {
}
}

function unrefNested(ref: any): any {
return isRef(ref) ? unrefNested(ref.value) : ref
}

class MutableReactiveHandler extends BaseReactiveHandler {
constructor(isShallow = false) {
super(false, isShallow)
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@vue/runtime-core",
"name": "@cabloy/vue-runtime-core",
"version": "3.5.13",
"description": "@vue/runtime-core",
"main": "index.js",
Expand Down
14 changes: 13 additions & 1 deletion packages/runtime-core/src/apiAsyncComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export interface AsyncComponentOptions<T = any> {
export const isAsyncWrapper = (i: ComponentInternalInstance | VNode): boolean =>
!!(i.type as ComponentOptions).__asyncLoader

function _getValidZova(instance: ComponentInternalInstance | null) {
while (instance) {
if ((<any>instance).zova) return (<any>instance).zova
instance = instance.parent
}
}

/*! #__NO_SIDE_EFFECTS__ */
export function defineAsyncComponent<
T extends Component = { new (): ComponentPublicInstance },
Expand Down Expand Up @@ -134,7 +141,12 @@ export function defineAsyncComponent<
if (resolvedComp) {
doHydrate()
} else {
load().then(() => !instance.isUnmounted && doHydrate())
const zova = _getValidZova(instance)
zova.meta.ssr._hydratingInc()
load().then(() => {
!instance.isUnmounted && doHydrate()
zova.meta.ssr._hydratingDec()
})
}
},

Expand Down
3 changes: 3 additions & 0 deletions packages/runtime-core/src/apiLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const createHook =
) {
injectHook(lifecycle, (...args: unknown[]) => hook(...args), target)
}
if (lifecycle === 'm' && target && target.isMounted) {
hook()
}
}
type CreateHook<T = any> = (
hook: T,
Expand Down
13 changes: 8 additions & 5 deletions packages/runtime-core/src/componentSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ const normalizeSlot = (
currentInstance &&
(!ctx || ctx.root === currentInstance.root)
) {
warn(
`Slot "${key}" invoked outside of the render function: ` +
`this will not track dependencies used in the slot. ` +
`Invoke the slot function inside the render function instead.`,
)
// eslint-disable-next-line
if (typeof window !== 'undefined') {
warn(
`Slot "${key}" invoked outside of the render function: ` +
`this will not track dependencies used in the slot. ` +
`Invoke the slot function inside the render function instead.`,
)
}
}
return normalizeSlotValue(rawSlot(...args))
}, ctx) as Slot
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ export const TeleportImpl = {
} = vnode

if (target) {
hostRemove(targetStart!)
hostRemove(targetAnchor!)
targetStart && hostRemove(targetStart!)
targetAnchor && hostRemove(targetAnchor!)
}

// an unmounted teleport should always unmount its children whether it's disabled or not
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime-core/src/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ function reload(id: string, newComp: HMRComponent): void {
instance.ceReload((newComp as any).styles)
dirtyInstances.delete(instance)
} else if (instance.parent) {
const app = <any>instance.appContext.app
app.zova && app.zova.reloadDelay(true)
// 4. Force the parent instance to re-render. This will cause all updated
// components to be unmounted and re-mounted. Queue the update so that we
// don't end up forcing the same parent to re-render multiple times.
Expand Down
62 changes: 44 additions & 18 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,16 @@ export function createHydrationFunctions(
}
} else {
if ((node as Text).data !== vnode.children) {
;(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
warn(
`Hydration text mismatch in`,
node.parentNode,
`\n - rendered on server: ${JSON.stringify(
(node as Text).data,
)}` +
`\n - expected on client: ${JSON.stringify(vnode.children)}`,
)
logMismatchError()
// ;(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
// warn(
// `Hydration text mismatch in`,
// node.parentNode,
// `\n - rendered on server: ${JSON.stringify(
// (node as Text).data,
// )}` +
// `\n - expected on client: ${JSON.stringify(vnode.children)}`,
// )
// logMismatchError()
;(node as Text).data = vnode.children as string
}
nextNode = nextSibling(node)
Expand Down Expand Up @@ -364,6 +364,13 @@ export function createHydrationFunctions(
return nextNode
}

function _getValidZova(instance: ComponentInternalInstance | null) {
while (instance) {
if ((<any>instance).zova) return (<any>instance).zova
instance = instance.parent
}
}

const hydrateElement = (
el: Element,
vnode: VNode,
Expand Down Expand Up @@ -485,14 +492,33 @@ export function createHydrationFunctions(
const isCustomElement = el.tagName.includes('-')
for (const key in props) {
// check hydration mismatch
if (
(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
// #11189 skip if this node has directives that have created hooks
// as it could have mutated the DOM in any possible way
!(dirs && dirs.some(d => d.dir.created)) &&
propHasMismatch(el, key, props[key], vnode, parentComponent)
) {
logMismatchError()
let ignore
let clientValue = props[key]
const zova = _getValidZova(parentComponent)
if (zova) {
const res = zova.meta.ssr._hydratePropHasMismatch(
el,
key,
clientValue,
vnode,
parentComponent,
)
if (res.ignore) {
ignore = true
} else {
clientValue = res.clientValue
}
}
if (!ignore) {
if (
(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
// #11189 skip if this node has directives that have created hooks
// as it could have mutated the DOM in any possible way
!(dirs && dirs.some(d => d.dir.created)) &&
propHasMismatch(el, key, props[key], vnode, parentComponent)
) {
logMismatchError()
}
}
if (
(forcePatch &&
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export {

// For getting a hold of the internal instance in setup() - useful for advanced
// plugins
export { getCurrentInstance } from './component'
export { getCurrentInstance, setCurrentInstance } from './component'

// For raw render function users
export { h } from './h'
Expand Down
49 changes: 45 additions & 4 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,13 @@ function baseCreateRenderer(
}
}

function _getValidZova(instance: ComponentInternalInstance | null) {
while (instance) {
if ((<any>instance).zova) return (<any>instance).zova
instance = instance.parent
}
}

const setupRenderEffect: SetupRenderEffectFn = (
instance,
initialVNode,
Expand Down Expand Up @@ -1308,7 +1315,10 @@ function baseCreateRenderer(
}
toggleRecurse(instance, true)

if (el && hydrateNode) {
const _zova = _getValidZova(instance)
const _maybeAllowHydrate =
!_zova || _zova.meta.ssr.isRuntimeSsrPreHydration
if (el && hydrateNode && _maybeAllowHydrate) {
// vnode has adopted host node - perform hydration instead of mount.
const hydrateSubTree = () => {
if (__DEV__) {
Expand Down Expand Up @@ -1343,7 +1353,16 @@ function baseCreateRenderer(
hydrateSubTree,
)
} else {
hydrateSubTree()
const zova = (<any>instance).zova
if (zova) {
zova.meta.ssr._hydratingInc()
zova.meta.state.inited.wait().then(() => {
!instance.isUnmounted && hydrateSubTree()
zova.meta.ssr._hydratingDec()
})
} else {
hydrateSubTree()
}
}
} else {
// custom element style injection
Expand Down Expand Up @@ -1431,6 +1450,14 @@ function baseCreateRenderer(
} else {
let { next, bu, u, parent, vnode } = instance

const zova = (<any>instance).zova
if (zova && zova.meta.ssr.isRuntimeSsrPreHydration) {
return
}
if (!instance.subTree) {
return
}

if (__FEATURE_SUSPENSE__) {
const nonHydratedAsyncRoot = locateNonHydratedAsyncRoot(instance)
// we are trying to update some async comp before hydration
Expand Down Expand Up @@ -1557,8 +1584,22 @@ function baseCreateRenderer(
const effect = (instance.effect = new ReactiveEffect(componentUpdateFn))
instance.scope.off()

const update = (instance.update = effect.run.bind(effect))
const job: SchedulerJob = (instance.job = effect.runIfDirty.bind(effect))
function _patchUpdate(checkDirty: boolean) {
if (!checkDirty || effect.dirty) {
const zova = _getValidZova(instance)
if (
zova &&
zova.meta.ssr.isRuntimeSsrPreHydration &&
!zova.meta.ssr._hydratingInstanceRecord(instance)
) {
return
}
effect.run()
}
}

const update = (instance.update = () => _patchUpdate(false))
const job: SchedulerJob = (instance.job = () => _patchUpdate(true))
job.i = instance
job.id = instance.uid
effect.scheduler = () => queueJob(job)
Expand Down

0 comments on commit 221a8d3

Please sign in to comment.