Skip to content

Commit

Permalink
Release: 2.7.3 (#561)
Browse files Browse the repository at this point in the history
* fix: 🐛 simply copy callable functions extra properties (#557)
* fix: 🐛 append missing styles (#560)
* fix: 🐛 empty value or undefined in activePath array should be ignored (#559)
  • Loading branch information
maoxiaoke authored Apr 7, 2022
1 parent 698b7b5 commit 88b39bc
Show file tree
Hide file tree
Showing 23 changed files with 113 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
1 change: 0 additions & 1 deletion packages/icestark/__tests__/AppRouter.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ describe('AppRouter', () => {
unmount();
})


test('app-multi-paths', async () => {
(fetch as FetchMock).mockResponseOnce(umdSourceWithSetLibrary.toString());
const { container, unmount } = render(
Expand Down
12 changes: 12 additions & 0 deletions packages/icestark/__tests__/checkActive.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
});
1 change: 1 addition & 0 deletions packages/icestark/__tests__/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion packages/icestark/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/icestark/src/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export default class AppRouter extends React.Component<AppRouterProps, AppRouter
}
});


if (match) {
const { name, activePath, path } = element.props as AppRouteProps;

Expand Down
11 changes: 10 additions & 1 deletion packages/icestark/src/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ async function loadApp(app: MicroApp) {
}
} catch (err) {
configuration.onError(err);
log.error(err);
updateAppConfig(name, { status: LOAD_ERROR });
}
if (lifeCycle.mount) {
Expand Down Expand Up @@ -380,7 +381,15 @@ export async function createMicroApp(
break;
case UNMOUNTED:
if (!appConfig.cached) {
await loadAndAppendCssAssets(appConfig?.appAssets?.cssList || [], {
const appendAssets = [
...(appConfig?.appAssets?.cssList || []),
// In vite development mode, styles are inserted into DOM manually.
// While es module natively imported twice may never excute twice.
// https://github.com/ice-lab/icestark/issues/555
...(appConfig?.loadScriptMode === 'import' ? filterRemovedAssets(importCachedAssets[appConfig.name] ?? [], ['LINK', 'STYLE']) : []),
];

await loadAndAppendCssAssets(appendAssets, {
cacheCss: shouldCacheCss(appConfig.loadScriptMode),
fetch,
});
Expand Down
16 changes: 14 additions & 2 deletions packages/icestark/src/util/checkActive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pathToRegexp from 'path-to-regexp';
import urlParse from 'url-parse';
import { isFunction, toArray, isObject, addLeadingSlash } from './helpers';
import { ErrorCode, formatErrMessage } from './error';
import { isFunction, toArray, isObject, addLeadingSlash, log, isDev } from './helpers';

/**
* "slash" - hashes like #/ and #/sunshine/lollipops
Expand Down Expand Up @@ -97,7 +98,18 @@ const findActivePath = (activePath?: PathData[] | ActiveFn): (url?: string) => 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;
Expand Down
1 change: 1 addition & 0 deletions packages/icestark/src/util/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down
5 changes: 5 additions & 0 deletions packages/sandbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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`.
Expand Down
22 changes: 22 additions & 0 deletions packages/sandbox/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
2 changes: 1 addition & 1 deletion packages/sandbox/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
13 changes: 11 additions & 2 deletions packages/sandbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion website/docs/guide/use-child/others.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 应用
Expand Down
2 changes: 1 addition & 1 deletion website/docs/guide/use-child/vue.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion website/src/codes/2.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

export default function Error1({ args }) {
export default function Error2({ args }) {
return (
<>
<h1>#2: You can not use loadScriptMode = import where dynamic import is not supported by browsers.</h1>
Expand Down
2 changes: 1 addition & 1 deletion website/src/codes/3.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

export default function Error1({ args }) {
export default function Error3({ args }) {
return (
<>
<h1>#3: window.fetch not found, you need to polyfill it!</h1>
Expand Down
2 changes: 1 addition & 1 deletion website/src/codes/4.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

export default function Error1({ args }) {
export default function Error4({ args }) {
return (
<>
<h1>#4: Can not find app {args[0]} when call {args[1]}.</h1>
Expand Down
2 changes: 1 addition & 1 deletion website/src/codes/5.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import CodeSnippet from './CodeSnippet'

export default function Error1({ args }) {
export default function Error5({ args }) {
return (
<>
<h1>#5: The script resources loaded error:{args[0]}</h1>
Expand Down
2 changes: 1 addition & 1 deletion website/src/codes/6.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import CodeSnippet from './CodeSnippet'

export default function Error1({ args }) {
export default function Error6({ args }) {
return (
<>
<h1>#6: The stylesheets loaded error:{args[0]}</h1>
Expand Down
15 changes: 15 additions & 0 deletions website/src/codes/7.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

export default function Error7({ args }) {
return (
<>
<h1>#7: Each item of activePath must be string、object、array or a function.</h1>

<p>警告表达的含义是:activePath 接收的参数错误,应该是字符串、对象,数组或函数类型。</p>
<br />
<h2>解决办法</h2>

<p> activePath 接受到的参数可能是 undefind、null 或者空字符。详见 activePath 可配置的 <a href="/docs/api/ice-stark#activePath">参数</a> </p>
</>
);
}

0 comments on commit 88b39bc

Please sign in to comment.