Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ See [https://github.com/ice-lab/icestark/releases](https://github.com/ice-lab/ic

## 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
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
1 change: 1 addition & 0 deletions 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
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 (matchPath && 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 ${matchPath?.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
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>
</>
);
}