diff --git a/CHANGELOG.md b/CHANGELOG.md index d912570d..72124cc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ See [https://github.com/ice-lab/icestark/releases](https://github.com/ice-lab/icestark/releases) for what has changed in each version of icestark. +## 2.7.3 + +- [fix] empty value or `undefined` in `activePath` array will be ignored. ([#558](https://github.com/ice-lab/icestark/issues/558)) +- [fix] append missing styles in vite developing mode. ([#555](https://github.com/ice-lab/icestark/issues/555)) + ## 2.7.2 - [fix] set actual basename when `activePath` is an array. ([#526](https://github.com/ice-lab/icestark/issues/526)) diff --git a/package.json b/package.json index 74954424..f22cbb24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "icestark-monorepo", - "version": "2.7.2", + "version": "2.7.3", "private": true, "description": "Icestark is a JavaScript library for multiple projects, Ice workbench solution.", "scripts": { diff --git a/packages/icestark/__tests__/AppRouter.spec.tsx b/packages/icestark/__tests__/AppRouter.spec.tsx index 89becb49..43b731ce 100644 --- a/packages/icestark/__tests__/AppRouter.spec.tsx +++ b/packages/icestark/__tests__/AppRouter.spec.tsx @@ -121,7 +121,6 @@ describe('AppRouter', () => { unmount(); }) - test('app-multi-paths', async () => { (fetch as FetchMock).mockResponseOnce(umdSourceWithSetLibrary.toString()); const { container, unmount } = render( diff --git a/packages/icestark/__tests__/checkActive.spec.tsx b/packages/icestark/__tests__/checkActive.spec.tsx index f464df0f..22845a92 100644 --- a/packages/icestark/__tests__/checkActive.spec.tsx +++ b/packages/icestark/__tests__/checkActive.spec.tsx @@ -97,5 +97,17 @@ describe('checkActive', () => { // matched idx checkFnc = findActivePath(formatPath(['/test', '/seller'], {})); expect(checkFnc('/seller')).toEqual('/seller'); + + // undefined array + checkFnc = findActivePath(formatPath([undefined, '/seller'], {})); + expect(checkFnc('/')).toBeFalsy(); + + // nuallable array + checkFnc = findActivePath(formatPath([null, '/seller'], {})); + expect(checkFnc('/')).toBeFalsy(); + + // empty array + checkFnc = findActivePath(formatPath(['', '/seller'], {})); + expect(checkFnc('/')).toBeFalsy(); }) }); diff --git a/packages/icestark/__tests__/index.spec.tsx b/packages/icestark/__tests__/index.spec.tsx index 0a02c5a8..acacdffe 100644 --- a/packages/icestark/__tests__/index.spec.tsx +++ b/packages/icestark/__tests__/index.spec.tsx @@ -149,6 +149,7 @@ describe('AppRouter', () => { expect(container.innerHTML).toContain('test render b'); unmount(); }); + test('test for AppRoute entry -> success', done => { window.history.pushState({}, 'test', '/fetch-entry'); diff --git a/packages/icestark/package.json b/packages/icestark/package.json index a704f803..9c4a6e2f 100644 --- a/packages/icestark/package.json +++ b/packages/icestark/package.json @@ -1,6 +1,6 @@ { "name": "@ice/stark", - "version": "2.7.2", + "version": "2.7.3", "description": "Icestark is a JavaScript library for multiple projects, Ice workbench solution.", "scripts": { "build": "rm -rf lib && tsc", diff --git a/packages/icestark/src/AppRouter.tsx b/packages/icestark/src/AppRouter.tsx index 908302b0..3294dec0 100644 --- a/packages/icestark/src/AppRouter.tsx +++ b/packages/icestark/src/AppRouter.tsx @@ -231,7 +231,6 @@ export default class AppRouter extends React.Component s let matchedPath; const isActive = activePath.some((path) => { matchedPath = path?.value; - return matchPath(url, path); + + if (!matchedPath && isDev) { + log.warn( + formatErrMessage( + ErrorCode.ACTIVE_PATH_ITEM_CAN_NOT_BE_EMPTY, + `Each item of activePath must be string、object、array or a function. Received ${matchedPath?.toString()}`, + ), + ); + } + + // Escape when path is empty or undefined + return matchedPath ? matchPath(url, path) : false; }); return isActive ? matchedPath : false; diff --git a/packages/icestark/src/util/error.ts b/packages/icestark/src/util/error.ts index 9d5b16c6..c8b19c9a 100644 --- a/packages/icestark/src/util/error.ts +++ b/packages/icestark/src/util/error.ts @@ -5,6 +5,7 @@ export enum ErrorCode { 'CANNOT_FIND_APP' = 4, 'JS_LOAD_ERROR' = 5, 'CSS_LOAD_ERROR' = 6, + 'ACTIVE_PATH_ITEM_CAN_NOT_BE_EMPTY' = 7, } export function normalizeMsg(msg: string, args: string[]) { diff --git a/packages/sandbox/CHANGELOG.md b/packages/sandbox/CHANGELOG.md index f815e66e..0526bbe6 100644 --- a/packages/sandbox/CHANGELOG.md +++ b/packages/sandbox/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.4 + +- [fix] simply copy callable funtions's extra properties. + ## 1.1.2 - [fix] hijacked eventListener were not been removed after sandbox unload. ([#295](https://github.com/ice-lab/icestark/issues/295)) @@ -9,6 +13,7 @@ ## 1.1.1 - [fix] falsy values except `undefined` would be trapped by proxy window. ([#156](https://github.com/ice-lab/icestark/issues/156)) + ## 1.1.0 - [feat] mark access to all properties added to local window by using method `getAddedProperties`. diff --git a/packages/sandbox/__tests__/index.spec.ts b/packages/sandbox/__tests__/index.spec.ts index eb5f76e2..fea1ee99 100644 --- a/packages/sandbox/__tests__/index.spec.ts +++ b/packages/sandbox/__tests__/index.spec.ts @@ -129,3 +129,25 @@ describe('eval in sandbox', () => { }); }); +describe('callable functions in sandbox', () => { + const sandbox = new Sandbox({ multiMode: true }); + + test('callable function with extra properties', () => { + // @ts-ignore + window.axios = function(){}; + // @ts-ignore + axios.create = function(){}; + let error = null; + try { + sandbox.execScriptInSandbox( + ` + axios.create(); + `, + ); + } catch (e) { + error = e.message; + } + + expect(error).toBe(null); + }); +}); diff --git a/packages/sandbox/package.json b/packages/sandbox/package.json index 1349b93f..9433e009 100644 --- a/packages/sandbox/package.json +++ b/packages/sandbox/package.json @@ -1,6 +1,6 @@ { "name": "@ice/sandbox", - "version": "1.1.3", + "version": "1.1.4", "description": "sandbox for execute scripts", "main": "lib/index.js", "scripts": { diff --git a/packages/sandbox/src/index.ts b/packages/sandbox/src/index.ts index 6f0b81c8..b91cf98e 100644 --- a/packages/sandbox/src/index.ts +++ b/packages/sandbox/src/index.ts @@ -153,8 +153,17 @@ export default class Sandbox { } if (isWindowFunction(value)) { - // fix Illegal invocation - return value.bind(originalWindow); + // When run into some window's functions, such as `console.table`, + // an illegal invocation exception is thrown. + const boundValue = value.bind(originalWindow); + + // Axios, Moment, and other callable functions may have additional properties. + // Simply copy them into boundValue. + for (const key in value) { + boundValue[key] = value[key]; + } + + return boundValue; } else { // case of window.clientWidth、new window.Object() return value; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 506ea685..60c2abf6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,7 +74,7 @@ importers: typescript: ^4.3.5 url-parse: ^1.1.9 dependencies: - '@ice/sandbox': link:../sandbox + '@ice/sandbox': 1.1.3 lodash.isempty: 4.4.0 lodash.isequal: 4.5.0 path-to-regexp: 1.8.0 @@ -106,7 +106,7 @@ importers: react-dom: ^16.13.1 typescript: ^3.8.3 dependencies: - '@ice/sandbox': link:../sandbox + '@ice/sandbox': 1.1.3 devDependencies: react: 16.14.0 react-dom: 16.14.0_react@16.14.0 @@ -625,6 +625,10 @@ packages: resolution: {integrity: sha1-tSBSnsIdjllFoYUd/Rwy6U45/0U=, tarball: '@humanwhocodes/object-schema/download/@humanwhocodes/object-schema-1.2.1.tgz'} dev: true + /@ice/sandbox/1.1.3: + resolution: {integrity: sha512-qC+1wZXLVPmneOuQ4nlMDhnmcq9L/JZFEahsyktZ0DveuWkhomREoM5fodGsyDpwDXregywEhzGatcU55AOtWw==} + dev: false + /@iceworks/eslint-plugin-best-practices/0.2.10_b0505e73fb80a469b12939b6b7fdc1f5: resolution: {integrity: sha512-5VyGibvZ9bkwBnijjG1oSo+iAuMi7dxlPUmPDiG2sYsENjQueMLjh7E180a7Ija2n7dWYRWhFpsAP/c93W8gcA==, tarball: '@iceworks/eslint-plugin-best-practices/download/@iceworks/eslint-plugin-best-practices-0.2.10.tgz'} dependencies: @@ -3136,7 +3140,7 @@ packages: dev: true /fsevents/1.2.13: - resolution: {integrity: sha1-8yXLBFVZJCi88Rs4M3DvcOO/zDg=, tarball: fsevents/download/fsevents-1.2.13.tgz} + resolution: {integrity: sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==} engines: {node: '>= 4.0'} os: [darwin] deprecated: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2. diff --git a/website/docs/guide/use-child/others.md b/website/docs/guide/use-child/others.md index ad42cda7..eb073d6e 100644 --- a/website/docs/guide/use-child/others.md +++ b/website/docs/guide/use-child/others.md @@ -13,7 +13,7 @@ order: 3 ## icejs 应用 -[icejs](https://ice.work/) 为 icestark 提供了专门的 [插件](https://ice.work/docs/guide/develop/plugin-dev)。更多有关 icejs 应用接入 icestark 的细节请参考 [微前端 icestark](https://ice.work/docs/guide/advance/icestark#%E5%BE%AE%E5%BA%94%E7%94%A8)。 +有关 [icejs]((https://ice.work/)) 应用接入 icestark 的细节请参考 [微前端 icestark](https://ice.work/docs/guide/advance/icestark#%E5%BE%AE%E5%BA%94%E7%94%A8)。 ## create-react-app 应用 diff --git a/website/docs/guide/use-child/vue.md b/website/docs/guide/use-child/vue.md index 34ae5e93..d77ddbeb 100644 --- a/website/docs/guide/use-child/vue.md +++ b/website/docs/guide/use-child/vue.md @@ -6,7 +6,7 @@ order: 2 ## 通过脚手架创建 -> 官方脚手架基于 Vue 2.0 + Vue CLI。 +> 脚手架基于 Vue 3.0 + Vite ```bash $ npm init ice icestark-child @vue-materials/icestark-child-app diff --git a/website/src/codes/2.jsx b/website/src/codes/2.jsx index 5eb36f04..c5007576 100644 --- a/website/src/codes/2.jsx +++ b/website/src/codes/2.jsx @@ -1,6 +1,6 @@ import React from 'react'; -export default function Error1({ args }) { +export default function Error2({ args }) { return ( <>

#2: You can not use loadScriptMode = import where dynamic import is not supported by browsers.

diff --git a/website/src/codes/3.jsx b/website/src/codes/3.jsx index f6c79fc6..38e98451 100644 --- a/website/src/codes/3.jsx +++ b/website/src/codes/3.jsx @@ -1,6 +1,6 @@ import React from 'react'; -export default function Error1({ args }) { +export default function Error3({ args }) { return ( <>

#3: window.fetch not found, you need to polyfill it!

diff --git a/website/src/codes/4.jsx b/website/src/codes/4.jsx index 52b0706e..b978089d 100644 --- a/website/src/codes/4.jsx +++ b/website/src/codes/4.jsx @@ -1,6 +1,6 @@ import React from 'react'; -export default function Error1({ args }) { +export default function Error4({ args }) { return ( <>

#4: Can not find app {args[0]} when call {args[1]}.

diff --git a/website/src/codes/5.jsx b/website/src/codes/5.jsx index 74ffb5e3..ac9a19ac 100644 --- a/website/src/codes/5.jsx +++ b/website/src/codes/5.jsx @@ -1,7 +1,7 @@ import React from 'react'; import CodeSnippet from './CodeSnippet' -export default function Error1({ args }) { +export default function Error5({ args }) { return ( <>

#5: The script resources loaded error:{args[0]}

diff --git a/website/src/codes/6.jsx b/website/src/codes/6.jsx index 54f79cb2..bacb7edb 100644 --- a/website/src/codes/6.jsx +++ b/website/src/codes/6.jsx @@ -1,7 +1,7 @@ import React from 'react'; import CodeSnippet from './CodeSnippet' -export default function Error1({ args }) { +export default function Error6({ args }) { return ( <>

#6: The stylesheets loaded error:{args[0]}

diff --git a/website/src/codes/7.jsx b/website/src/codes/7.jsx new file mode 100644 index 00000000..77650f58 --- /dev/null +++ b/website/src/codes/7.jsx @@ -0,0 +1,15 @@ +import React from 'react'; + +export default function Error7({ args }) { + return ( + <> +

#7: Each item of activePath must be string、object、array or a function.

+ +

警告表达的含义是:activePath 接收的参数错误,应该是字符串、对象,数组或函数类型。

+
+

解决办法

+ +

activePath 接受到的参数可能是 undefind、null 或者空字符。详见 activePath 可配置的 参数

+ + ); +}