Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: 2.8.0 #578

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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.8.0

- [fix] When icestark unloads, avoid re-triggering 'unloadMicroApp'. ([#521](https://github.com/ice-lab/icestark/issues/521))

## 2.7.5

- [fix] avoid to set undefined url when state change.
Expand Down Expand Up @@ -93,6 +97,7 @@ See [https://github.com/ice-lab/icestark/releases](https://github.com/ice-lab/ic
## 2.2.1

- [fix] css assets are unable to load when remove `umd` from sub-application.

## 2.2.0

- [feat] no need to use `umd` anymore. Migrate to `loadScriptMode` or use `setLibraryName` in sub-application. ([#240](https://github.com/ice-lab/icestark/issues/240))
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.3",
"version": "2.8.0",
"private": true,
"description": "Icestark is a JavaScript library for multiple projects, Ice workbench solution.",
"scripts": {
Expand Down
59 changes: 58 additions & 1 deletion packages/icestark/__tests__/AppRouter.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getCache, setCache } from '../src/util/cache';
import * as React from 'react';
import { render } from '@testing-library/react';
import { AppRouter, AppRoute } from '../src/index';
import { getMicroApps } from '../src/apps';

const delay = (milliscond: number) => new Promise(resolve => setTimeout(resolve, milliscond));

Expand Down Expand Up @@ -145,4 +146,60 @@ describe('AppRouter', () => {

unmount();
})
})

test('app-cached', async () => {
(fetch as FetchMock).mockResponseOnce(umdSourceWithSetLibrary.toString());
const { container, unmount } = render(
<AppRouter>
<AppRoute
loadScriptMode="fetch"
cached
name="seller"
path="/seller"
title="小二"
url={[
'//icestark.com/index.js'
]}
/>
</AppRouter>
);
window.history.pushState({}, 'test', '/seller');

await delay(1000);
expect(container.innerHTML).toContain('商家平台')

window.history.pushState({}, 'test', '/waiter');
await delay(1000);

const app = getMicroApps().find(app => app.name === 'seller');
expect(app.status).toEqual('UNMOUNTED');
expect(!!app.mount).toBeTruthy();
expect(!!app.unmount).toBeTruthy();

unmount();
})

test('app-className-custom', async () => {
(fetch as FetchMock).mockResponseOnce(umdSourceWithSetLibrary.toString());
const { container, unmount } = render(
<AppRouter className="ice-app-router-custom">
<AppRoute
loadScriptMode="fetch"
name="seller"
path="/seller"
title="小二"
url={[
'//icestark.com/index.js'
]}
/>
</AppRouter>
);

window.history.pushState({}, 'test', '/seller');
await delay(1000);

expect(container.querySelector('.ice-app-router-custom')).toBeTruthy();

unmount();
})
})
37 changes: 35 additions & 2 deletions packages/icestark/__tests__/app.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,38 @@ describe('app start', () => {

const errorApp = await createMicroApp('app-error');
expect(errorApp).toBe(null);
})
});
});

test('window.microApps should be equal to insider microApps', async () => {
let status = '';
registerMicroApps([
{
name: 'app7',
activePath: '/testapp',
url: ['//icestark.com/index.js'],
mount: () => {
status = MOUNTED;
},
unmount: () => {
status = UNMOUNTED;
},
} as AppConfig,
]);
window.history.pushState({}, 'test', '/testapp');
const findMicroAppByName = (microApps, name) => microApps.filter(d => d.name === name)[0];
await mountMicroApp('app7');
expect(status).toBe(MOUNTED);
expect(findMicroAppByName(getMicroApps(), 'app7').status).toEqual(findMicroAppByName((window as any).microApps, 'app7').status);
expect(findMicroAppByName(getMicroApps(), 'app7').status).toEqual(status);

await unmountMicroApp('app7');
expect(status).toBe(UNMOUNTED);
expect(findMicroAppByName(getMicroApps(), 'app7').status).toEqual(findMicroAppByName((window as any).microApps, 'app7').status);
expect(findMicroAppByName(getMicroApps(), 'app7').status).toEqual(status);

await createMicroApp('app7');
expect(status).toBe(MOUNTED);
expect(findMicroAppByName(getMicroApps(), 'app7').status).toEqual(findMicroAppByName((window as any).microApps, 'app7').status);
expect(findMicroAppByName(getMicroApps(), 'app7').status).toEqual(status);
});
});
44 changes: 0 additions & 44 deletions packages/icestark/__tests__/appLifeCycle.spec.tsx

This file was deleted.

20 changes: 13 additions & 7 deletions packages/icestark/__tests__/handleAssets.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,13 @@ describe('appendCSS', () => {
const div = document.createElement('div');

appendCSS(
div,
{
type: AssetTypeEnum.EXTERNAL,
content: '/test.css'
},
'icestark-css-0'
},{
root: div,
id: 'icestark-css-0'
}
)
.then(() => {
expect(div.innerHTML).toContain('id="icestark-css-0"');
Expand All @@ -671,10 +672,13 @@ describe('appendCSS', () => {
test('appendCSS -> style', () => {
const div = document.createElement('div');
const style = '.test { color: #fff;}';
appendCSS(div, {
appendCSS({
type: AssetTypeEnum.INLINE,
content: style,
}, 'icestark-css-0')
}, {
root: div,
id: 'icestark-css-0'
})
.then(() => {
expect(div.innerHTML).toContain('id="icestark-css-0"');
expect(div.innerHTML).toContain(style);
Expand All @@ -694,12 +698,14 @@ describe('appendCSS', () => {
const div = document.createElement('div');

appendCSS(
div,
{
type: AssetTypeEnum.EXTERNAL,
content: '/test.css'
},
'icestark-css-0'
{
root: div,
id: 'icestark-css-0'
}
)
.then(() => {
expect(div.innerHTML).toContain('id="icestark-css-0"');
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.5",
"version": "2.8.0",
"description": "Icestark is a JavaScript library for multiple projects, Ice workbench solution.",
"scripts": {
"build": "rm -rf lib && tsc",
Expand Down
15 changes: 10 additions & 5 deletions packages/icestark/src/AppRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as React from 'react';
import renderComponent from './util/renderComponent';
import { AppHistory } from './appHistory';
import { unloadMicroApp, BaseConfig, createMicroApp } from './apps';
import { unloadMicroApp, unmountMicroApp, BaseConfig, createMicroApp } from './apps';
import { converArray2String } from './util/helpers';
import { callCapturedEventListeners, resetCapturedEventListeners } from './util/capturedListeners';
import { started } from './start';
import {
callCapturedEventListeners,
resetCapturedEventListeners,
} from './util/capturedListeners';
import isEqual from 'lodash.isequal';

import type { PathData } from './util/checkActive';
Expand Down Expand Up @@ -136,6 +140,7 @@ export default class AppRoute extends React.Component<AppRouteProps, AppRouteSta

mountApp = () => {
resetCapturedEventListeners();

const { onAppEnter } = this.props;

// Trigger app enter
Expand All @@ -151,15 +156,15 @@ export default class AppRoute extends React.Component<AppRouteProps, AppRouteSta
};

unmountApp = () => {
const { name, onAppLeave } = this.props;
const { name, onAppLeave, cached } = this.props;

// Trigger app leave
if (typeof onAppLeave === 'function') {
onAppLeave(genCompatibleAppConfig(this.props));
}

if (!this.validateRender()) {
unloadMicroApp(name);
if (!this.validateRender() && started) {
cached ? unmountMicroApp(name) : unloadMicroApp(name);
}
};

Expand Down
4 changes: 3 additions & 1 deletion packages/icestark/src/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface AppRouterProps {
basename?: string;
fetch?: Fetch;
prefetch?: Prefetch;
className?: string;
}

interface AppRouterState {
Expand Down Expand Up @@ -195,6 +196,7 @@ export default class AppRouter extends React.Component<AppRouterProps, AppRouter
LoadingComponent,
children,
basename: frameworkBasename,
className,
} = this.props;
const { url, appLoading, started } = this.state;

Expand Down Expand Up @@ -249,7 +251,7 @@ export default class AppRouter extends React.Component<AppRouterProps, AppRouter
history: appHistory,
};
return (
<div>
<div className={className}>
{appLoading === this.appKey ? renderComponent(LoadingComponent, {}) : null}
{React.cloneElement(element, {
key: this.appKey,
Expand Down
Loading
Loading