Skip to content

Commit

Permalink
release: 2.6.2 (#408)
Browse files Browse the repository at this point in the history
* feat: 🎸 prevent duplicate appends some resources (#372)

* fix: 🐛 bind history to window (#428)

* fix: 🐛 prefetchApp's fetch should be optional (#388)
  • Loading branch information
maoxiaoke committed Oct 27, 2021
1 parent a02c295 commit 2ad2ff3
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

- [fix] avoid to append duplicate assets. ([#331](https://github.com/ice-lab/icestark/issues/331))
- [fix] bind `pushState` to global. ([#426](https://github.com/ice-lab/icestark/issues/426))
- [fix] prefetch apps using `window.fetch` by default.

## 2.6.1

- [fix] wrap `import` using `new Function` to avoid compiler error under chrome61 & ie. ([#404](https://github.com/ice-lab/icestark/issues/404))
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": "@ice/stark",
"version": "2.6.1",
"version": "2.6.2",
"description": "Icestark is a JavaScript library for multiple projects, Ice workbench solution.",
"scripts": {
"install:deps": "rm -rf node_modules && rm -rf ./packages/*/node_modules && yarn install && lerna exec -- npm install",
Expand Down
4 changes: 4 additions & 0 deletions packages/icestark-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.2

- [fix] Bind history to window when using `AppLink`. ([#428](https://github.com/ice-lab/icestark/pull/428))

## 1.4.1

- [feat] correct types of `setLibraryName`. ([#287](https://github.com/ice-lab/icestark/issues/287))
Expand Down
2 changes: 1 addition & 1 deletion packages/icestark-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/stark-app",
"version": "1.4.1",
"version": "1.4.2",
"description": "icestark-app is a JavaScript library for icestark, used by sub-application.",
"scripts": {
"build": "rm -rf lib && tsc",
Expand Down
5 changes: 4 additions & 1 deletion packages/icestark-app/src/AppLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const AppLink = (props: AppLinkProps) => {
return false;
}

const changeState = window.history[replace ? 'replaceState' : 'pushState'];
/*
* Bind `replaceState` and `pushState` to window to avoid illegal invocation error
*/
const changeState = window.history[replace ? 'replaceState' : 'pushState'].bind(window);

changeState({}, null, linkTo);
}}
Expand Down
7 changes: 5 additions & 2 deletions src/AppLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ const AppLink: React.SFC<AppLinkProps> = (props: AppLinkProps) => {
<a
{...rest}
href={linkTo}
onClick={e => {
onClick={(e) => {
e.preventDefault();
if (message && window.confirm(message) === false) {
return false;
}

const changeState = window.history[replace ? 'replaceState' : 'pushState'];
/*
* Bind `replaceState` and `pushState` to window to avoid illegal invocation error
*/
const changeState = window.history[replace ? 'replaceState' : 'pushState'].bind(window);

changeState({}, null, linkTo);
}}
Expand Down
20 changes: 20 additions & 0 deletions src/util/handleAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ export interface ILifecycleProps {
customProps?: object;
}

function isAssetExist(element: HTMLScriptElement | HTMLLIElement, type: 'script' | 'link') {
const urlAlias = type === 'script' ? 'src' : 'href';

return Array.from(document.getElementsByTagName(type))
.some((item) => {
if (
item[urlAlias]
&& element[urlAlias] === item[urlAlias]
) {
return true;
}
return false;
});
}

/**
* Create link/style element and append to root
*/
Expand Down Expand Up @@ -235,6 +250,11 @@ export function appendExternalScript(asset: string | Asset,
scriptAttributes,
});

if (isAssetExist(element, 'script')) {
resolve();
return;
}

element.addEventListener(
'error',
() => reject(new Error(`js asset loaded error: ${content || asset}`)),
Expand Down
2 changes: 1 addition & 1 deletion src/util/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function doPrefetch(
}
}

export function prefetchApps(apps: AppConfig[], fetch: Fetch) {
export function prefetchApps(apps: AppConfig[], fetch: Fetch = window.fetch) {
if (apps && Array.isArray(apps)) {
apps.forEach(prefetchIdleTask(fetch));
}
Expand Down
31 changes: 31 additions & 0 deletions tests/handleAssets.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,37 @@ describe('appendAssets', () => {
Promise.all([loadAndAppendCssAssets(assets.cssList), loadAndAppendJsAssets(assets, {})])
});

test('appendAssets - duplicate', done => {
emptyAssets(() => true, true);
const assets = getUrlAssets([
'http://icestark.com/js/index.js',
'http://icestark.com/js/index.js',
'http://icestark.com/css/index.css',
'http://icestark.com/js/test1.js',
'http://icestark.com/js/test1.js',
]);
Promise.all([loadAndAppendCssAssets(assets.cssList), loadAndAppendJsAssets(assets, {})])
.then(() => {
const scripts = document.getElementsByTagName('script');
const styleSheets = document.getElementsByTagName('link');

expect(scripts.length).toBe(2);
expect(styleSheets.length).toBe(1);

emptyAssets(() => true, true);

done();
});

const links = Array.from(document.getElementsByTagName('link') || []);
const scripts = Array.from(document.getElementsByTagName('script') || [])
const linksAndScripts = links.concat(scripts as any);
for (let i = 0; i < linksAndScripts.length; i++) {
(linksAndScripts[i] as HTMLLinkElement | HTMLScriptElement).dispatchEvent(new Event('load'));
}

});

test('recordAssets', () => {
const jsElement = document.createElement('script');
jsElement.id = 'icestark-script';
Expand Down

0 comments on commit 2ad2ff3

Please sign in to comment.