Skip to content

Commit

Permalink
fix(vue-next): fix vuejs ugrade issue
Browse files Browse the repository at this point in the history
1. fix vuejs 3.4.32 patchProps API change issue
2. compatible vuejs compiler-core API change issue
3. upgrade vue-next demo package version
  • Loading branch information
gguoyu committed Aug 26, 2024
1 parent ac3fd3d commit d89a8ce
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 62 deletions.
8 changes: 4 additions & 4 deletions driver/js/examples/hippy-vue-next-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"@hippy/vue-next": "v3.3-latest",
"@hippy/vue-router-next-history": "0.0.1",
"@hippy/web-renderer": "latest",
"@vue/runtime-core": "^3.2.46",
"@vue/shared": "^3.2.46",
"vue": "^3.2.46",
"@vue/runtime-core": "^3.4.32",
"@vue/shared": "^3.4.32",
"vue": "^3.4.32",
"vue-router": "^4.0.12"
},
"devDependencies": {
Expand All @@ -43,7 +43,7 @@
"@hippy/vue-css-loader": "v3.3-latest",
"@vitejs/plugin-vue": "^1.9.4",
"@vue/cli-service": "^4.5.19",
"@vue/compiler-sfc": "^3.2.46",
"@vue/compiler-sfc": "^3.4.32",
"babel-loader": "^8.1.0",
"case-sensitive-paths-webpack-plugin": "^2.2.0",
"clean-webpack-plugin": "^4.0.0",
Expand Down
12 changes: 6 additions & 6 deletions driver/js/packages/hippy-vue-next-compiler-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"README.md"
],
"peerDependencies": {
"@vue/compiler-core": "^3.2.46",
"@vue/compiler-dom": "^3.2.46",
"@vue/shared": "^3.2.46"
"@vue/compiler-core": "^3.4.32",
"@vue/compiler-dom": "^3.4.32",
"@vue/shared": "^3.4.32"
},
"devDependencies": {
"@vue/compiler-core": "^3.2.46",
"@vue/compiler-dom": "^3.2.46",
"@vue/shared": "^3.2.46"
"@vue/compiler-core": "^3.4.32",
"@vue/compiler-dom": "^3.4.32",
"@vue/shared": "^3.4.32"
},
"jest": {
"moduleNameMapper": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
type RootNode,
type TemplateChildNode,
findDir,
isBuiltInType,
} from '@vue/compiler-dom';

export const ssrInjectCssVars: NodeTransform = (node, context) => {
Expand Down Expand Up @@ -65,7 +64,7 @@ function injectCssVars(node: RootNode | TemplateChildNode) {
|| node.tagType === ElementTypes.COMPONENT)
&& !findDir(node, 'for')
) {
if (isBuiltInType(node.tag, 'Suspense')) {
if (node.tag === 'suspense' || node.tag === 'Suspense') {
for (const child of node.children) {
if (
child.type === NodeTypes.ELEMENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
type TemplateChildNode,
type ParentNode,
findDir,
isBuiltInType,
} from '@vue/compiler-dom';

const filterChild = (node: ParentNode) => node.children.filter(n => n.type !== NodeTypes.COMMENT);
Expand All @@ -49,8 +48,10 @@ export const ssrInjectFallthroughAttrs: NodeTransform = (node, context) => {
if (
node.type === NodeTypes.ELEMENT
&& node.tagType === ElementTypes.COMPONENT
&& (isBuiltInType(node.tag, 'Transition')
|| isBuiltInType(node.tag, 'KeepAlive'))
&& (node.tag === 'transition'
|| node.tag === 'Transition'
|| node.tag === 'KeepAlive'
|| node.tag === 'keep-alive')
) {
const rootChildren = filterChild(context.root);
if (rootChildren.length === 1 && rootChildren[0] === node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ import {
type JSChildNode,
RESOLVE_DYNAMIC_COMPONENT,
TRANSITION,
type DirectiveNode,
} from '@vue/compiler-dom';
import { isSymbol, isObject, isArray } from '@vue/shared';
import { isSymbol, isObject, isArray, extend } from '@vue/shared';

import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers';
import {
Expand Down Expand Up @@ -149,8 +150,8 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
// fallback in case the child is render-fn based). Store them in an array
// for later use.
if (clonedNode.children.length) {
buildSlots(clonedNode, context, (props, children) => {
vnodeBranches.push(createVNodeSlotBranch(props, children, context));
buildSlots(clonedNode, context, (props, vFor, children) => {
vnodeBranches.push(createVNodeSlotBranch(props, vFor, children, context));
return createFunctionExpression(undefined);
});
}
Expand All @@ -174,7 +175,7 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
const wipEntries: WIPSlotEntry[] = [];
wipMap.set(node, wipEntries);

const buildSSRSlotFn: SlotFnBuilder = (props, children, loc) => {
const buildSSRSlotFn: SlotFnBuilder = (props, _vForExp, children, loc) => {
const fn = createFunctionExpression(
[props ?? '_', '_push', '_parent', '_scopeId'],
undefined, // no return, assign body later
Expand Down Expand Up @@ -299,7 +300,8 @@ const vnodeDirectiveTransforms = {
};

function createVNodeSlotBranch(
props: ExpressionNode | undefined,
slotProps: ExpressionNode | undefined,
vFor: DirectiveNode | undefined,
children: TemplateChildNode[],
parentContext: TransformContext,
): ReturnStatement {
Expand All @@ -321,24 +323,29 @@ function createVNodeSlotBranch(
};

// wrap the children with a wrapper template for proper children treatment.
// important: provide v-slot="props" and v-for="exp" on the wrapper for
// proper scope analysis
const wrapperProps: TemplateNode['props'] = [];
if (slotProps) {
wrapperProps.push({
type: NodeTypes.DIRECTIVE,
name: 'slot',
exp: slotProps,
arg: undefined,
modifiers: [],
loc: locStub,
});
}
if (vFor) {
wrapperProps.push(extend({}, vFor));
}
const wrapperNode: TemplateNode = {
type: NodeTypes.ELEMENT,
ns: Namespaces.HTML,
tag: 'template',
tagType: ElementTypes.TEMPLATE,
isSelfClosing: false,
// important: provide v-slot="props" on the wrapper for proper
// scope analysis
props: [
{
type: NodeTypes.DIRECTIVE,
name: 'slot',
exp: props,
arg: undefined,
modifiers: [],
loc: locStub,
},
],
props: wrapperProps,
children,
loc: locStub,
codegenNode: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,24 @@ export function ssrTransformSuspense(
wipSlots: [],
};
wipMap.set(node, wipEntry);
wipEntry.slotsExp = buildSlots(node, context, (_props, children, loc) => {
const fn = createFunctionExpression(
[],
undefined, // no return, assign body later
true, // newline
false, // suspense slots are not treated as normal slots
loc,
);
wipEntry.wipSlots.push({
fn,
children,
});
return fn;
}).slots;
wipEntry.slotsExp = buildSlots(
node,
context,
(_props, _vForExp, children, loc) => {
const fn = createFunctionExpression(
[],
undefined, // no return, assign body later
true, // newline
false, // suspense slots are not treated as normal slots
loc,
);
wipEntry.wipSlots.push({
fn,
children,
});
return fn;
},
).slots;
}
};
}
Expand Down
13 changes: 6 additions & 7 deletions driver/js/packages/hippy-vue-next-server-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
"README.md"
],
"peerDependencies": {
"@vue/server-renderer": "^3.2.46",
"@vue/runtime-core": "^3.2.46",
"@vue/shared": "^3.2.46"
"@vue/server-renderer": "^3.4.32",
"@vue/runtime-core": "^3.4.32",
"@vue/shared": "^3.4.32"
},
"devDependencies": {
"@vue/server-renderer": "^3.2.46",
"@vue/runtime-core": "^3.2.46",
"@vue/shared": "^3.2.46",
"vue": "^3.2.46"
"@vue/server-renderer": "^3.4.32",
"@vue/runtime-core": "^3.4.32",
"@vue/shared": "^3.4.32"
},
"jest": {
"moduleNameMapper": {
Expand Down
4 changes: 2 additions & 2 deletions driver/js/packages/hippy-vue-next-style-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"url": "https://github.com/Tencent/Hippy/issues"
},
"peerDependencies": {
"@vue/shared": "^3.2.46"
"@vue/shared": "^3.4.32"
},
"devDependencies": {
"@vue/shared": "^3.2.46"
"@vue/shared": "^3.4.32"
},
"entry": "./src/index.ts",
"jest": {
Expand Down
8 changes: 4 additions & 4 deletions driver/js/packages/hippy-vue-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"README.md"
],
"peerDependencies": {
"@vue/runtime-core": "^3.2.46",
"@vue/shared": "^3.2.46"
"@vue/runtime-core": "^3.4.32",
"@vue/shared": "^3.4.32"
},
"devDependencies": {
"@vue/runtime-core": "^3.2.46",
"@vue/shared": "^3.2.46"
"@vue/runtime-core": "^3.4.32",
"@vue/shared": "^3.4.32"
},
"jest": {
"moduleNameMapper": {
Expand Down
3 changes: 0 additions & 3 deletions driver/js/packages/hippy-vue-next/src/patch-prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ import { patchAttr } from './modules/attrs';
import { patchClass } from './modules/class';
import { patchEvent } from './modules/events';
import { patchStyle } from './modules/style';
import type { HippyElement } from './runtime/element/hippy-element';
import type { HippyNode } from './runtime/node/hippy-node';

export function patchProp(
el: NeedToTyped,
key: string,
prevValue: NeedToTyped,
nextValue: NeedToTyped,
namespace: ElementNamespace,
prevChildren: VNode<HippyNode, HippyElement>[] | undefined,
parentComponent: ComponentInternalInstance | null,
): void {
// It should be noted that the values contained in prop here will have strings, numbers, arrays, objects, etc.
Expand Down

0 comments on commit d89a8ce

Please sign in to comment.