mirror of https://github.com/alibaba/ice.git
Compare commits
16 Commits
a710f8873b
...
6125acd55e
| Author | SHA1 | Date |
|---|---|---|
|
|
6125acd55e | |
|
|
ace5e1dd15 | |
|
|
0141336861 | |
|
|
7f302fa439 | |
|
|
0dd4aab050 | |
|
|
d55e34bc56 | |
|
|
b2d93c6ffe | |
|
|
72bfa88d17 | |
|
|
9b95b4c031 | |
|
|
22d1b49c9c | |
|
|
4569200caf | |
|
|
4a46a1251c | |
|
|
f1d4ba5359 | |
|
|
7dde0b1d48 | |
|
|
55f4c22033 | |
|
|
bfa60bd2b0 |
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@ice/runtime': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: support options for API useSuspenseData
|
||||||
|
|
@ -1,5 +1,17 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 3.6.5
|
||||||
|
|
||||||
|
- hotfix: add isPHA and isKraken env for backward compatibility.
|
||||||
|
|
||||||
|
## 3.6.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 0dd4aab0: refactor: add env for themis, delete PHA/Kraken, simplize WindVane
|
||||||
|
- Updated dependencies [d55e34bc]
|
||||||
|
- @ice/runtime@1.5.6
|
||||||
|
|
||||||
## 3.6.3
|
## 3.6.3
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@ice/app",
|
"name": "@ice/app",
|
||||||
"version": "3.6.3",
|
"version": "3.6.5",
|
||||||
"description": "provide scripts and configuration used by web framework ice",
|
"description": "provide scripts and configuration used by web framework ice",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./esm/index.js",
|
"main": "./esm/index.js",
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,16 @@ export const isByteDanceMicroApp = isClient && import.meta.target === 'bytedance
|
||||||
export const isBaiduSmartProgram = isClient && import.meta.target === 'baidu-smartprogram';
|
export const isBaiduSmartProgram = isClient && import.meta.target === 'baidu-smartprogram';
|
||||||
export const isKuaiShouMiniProgram = isClient && import.meta.target === 'kuaishou-miniprogram';
|
export const isKuaiShouMiniProgram = isClient && import.meta.target === 'kuaishou-miniprogram';
|
||||||
export const isWeChatMiniProgram = isClient && import.meta.target === 'wechat-miniprogram';
|
export const isWeChatMiniProgram = isClient && import.meta.target === 'wechat-miniprogram';
|
||||||
export const isKraken = isClient && import.meta.target === 'kraken';
|
|
||||||
export const isQuickApp = false; // Now ice.js will not implement quick app target.
|
export const isQuickApp = false; // Now ice.js will not implement quick app target.
|
||||||
export const isMiniApp = isAliMiniApp;// in universal-env, isMiniApp is equals to isAliMiniApp
|
export const isMiniApp = isAliMiniApp; // in universal-env, isMiniApp is equals to isAliMiniApp
|
||||||
|
export const isKraken = isClient && import.meta.target === 'kraken';
|
||||||
|
|
||||||
// Following variables are runtime executed envs.
|
// Following variables are runtime executed envs.
|
||||||
// See also @uni/env.
|
// See also @uni/env.
|
||||||
export const isPHA = isWeb && typeof pha === 'object';
|
export const isPHA = isWeb && typeof pha === 'object';
|
||||||
const ua = typeof navigator === 'object' ? navigator.userAgent || navigator.swuserAgent : '';
|
const ua = typeof navigator === 'object' ? navigator.userAgent || navigator.swuserAgent : '';
|
||||||
const wvRegExp = /.+AliApp\((\w+)\/((?:\d+\.)+\d+)\).* .*(WindVane)(?:\/((?:\d+\.)+\d+))?.*/;
|
export const isThemis = /Themis/.test(ua);
|
||||||
export const isWindVane = wvRegExp.test(ua) && isWeb && typeof WindVane !== 'undefined' && typeof WindVane.call !== 'undefined';
|
export const isWindVane = /WindVane/i.test(ua) && isWeb && typeof WindVane !== 'undefined' && typeof WindVane.call !== 'undefined';
|
||||||
// WindVane.call is a function while page importing lib-windvane
|
// WindVane.call is a function while page importing lib-windvane
|
||||||
export const isFRM = isMiniApp && isWeb && typeof my !== 'undefined' && typeof my.isFRM !== 'undefined';
|
export const isFRM = isMiniApp && isWeb && typeof my !== 'undefined' && typeof my.isFRM !== 'undefined';
|
||||||
|
|
||||||
|
|
@ -28,13 +28,14 @@ export default {
|
||||||
isNode,
|
isNode,
|
||||||
isWeex,
|
isWeex,
|
||||||
isKraken,
|
isKraken,
|
||||||
|
isPHA,
|
||||||
|
isThemis,
|
||||||
isMiniApp,
|
isMiniApp,
|
||||||
isByteDanceMicroApp,
|
isByteDanceMicroApp,
|
||||||
isBaiduSmartProgram,
|
isBaiduSmartProgram,
|
||||||
isKuaiShouMiniProgram,
|
isKuaiShouMiniProgram,
|
||||||
isWeChatMiniProgram,
|
isWeChatMiniProgram,
|
||||||
isQuickApp,
|
isQuickApp,
|
||||||
isPHA,
|
|
||||||
isWindVane,
|
isWindVane,
|
||||||
isFRM,
|
isFRM,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
# @ice/miniapp-react-dom
|
# @ice/miniapp-react-dom
|
||||||
|
|
||||||
|
## 1.1.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- @ice/miniapp-runtime@1.2.6
|
||||||
|
|
||||||
## 1.1.5
|
## 1.1.5
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@ice/miniapp-react-dom",
|
"name": "@ice/miniapp-react-dom",
|
||||||
"version": "1.1.5",
|
"version": "1.1.6",
|
||||||
"description": "like react-dom, but for miniapps.",
|
"description": "like react-dom, but for miniapps.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "./esm/index.d.ts",
|
"types": "./esm/index.d.ts",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 1.2.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [d55e34bc]
|
||||||
|
- @ice/runtime@1.5.6
|
||||||
|
|
||||||
## 1.2.5
|
## 1.2.5
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@ice/miniapp-runtime",
|
"name": "@ice/miniapp-runtime",
|
||||||
"version": "1.2.5",
|
"version": "1.2.6",
|
||||||
"description": "ice runtime for miniapps.",
|
"description": "ice runtime for miniapps.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "./esm/index.d.ts",
|
"types": "./esm/index.d.ts",
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,8 @@
|
||||||
"webpack-dev-server": "4.15.0"
|
"webpack-dev-server": "4.15.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@ice/app": "^3.6.3",
|
"@ice/app": "^3.6.4",
|
||||||
"@ice/runtime": "^1.5.4"
|
"@ice/runtime": "^1.5.6"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 1.2.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- @ice/miniapp-runtime@1.2.6
|
||||||
|
- @ice/miniapp-react-dom@1.1.6
|
||||||
|
|
||||||
## 1.2.6
|
## 1.2.6
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@ice/plugin-miniapp",
|
"name": "@ice/plugin-miniapp",
|
||||||
"version": "1.2.6",
|
"version": "1.2.7",
|
||||||
"description": "ice.js plugin for miniapp.",
|
"description": "ice.js plugin for miniapp.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
@ -50,8 +50,8 @@
|
||||||
"sax": "^1.2.4"
|
"sax": "^1.2.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ice/app": "^3.6.3",
|
"@ice/app": "^3.6.4",
|
||||||
"@ice/runtime": "^1.5.4",
|
"@ice/runtime": "^1.5.6",
|
||||||
"webpack": "^5.88.0"
|
"webpack": "^5.88.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
# @ice/runtime
|
# @ice/runtime
|
||||||
|
|
||||||
|
## 1.5.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- d55e34bc: feat: add suspense event dispatch in Suspense component
|
||||||
|
|
||||||
## 1.5.5
|
## 1.5.5
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@ice/runtime",
|
"name": "@ice/runtime",
|
||||||
"version": "1.5.5",
|
"version": "1.5.6",
|
||||||
"description": "Runtime module for ice.js",
|
"description": "Runtime module for ice.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "./esm/index.d.ts",
|
"types": "./esm/index.d.ts",
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,35 @@ const getHydrateData = (id: string) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useSuspenseData(request?: Request) {
|
class QueryClient {
|
||||||
|
queryCache: Map<string, Promise<any>>;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.queryCache = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
setQueryData(key: string, promise: Promise<any>) {
|
||||||
|
if (key) {
|
||||||
|
this.queryCache.set(key, promise);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getQueryData(key: string) {
|
||||||
|
return this.queryCache.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeQueryData(key: string) {
|
||||||
|
this.queryCache.delete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
|
interface SuspenseDataProps {
|
||||||
|
queryKey?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSuspenseData(request?: Request, options?: SuspenseDataProps) {
|
||||||
const appContext = useAppContext();
|
const appContext = useAppContext();
|
||||||
const { requestContext } = appContext;
|
const { requestContext } = appContext;
|
||||||
const suspenseState = React.useContext(SuspenseContext);
|
const suspenseState = React.useContext(SuspenseContext);
|
||||||
|
|
@ -55,22 +83,26 @@ export function useSuspenseData(request?: Request) {
|
||||||
const { data, done, promise, update, error, id } = suspenseState;
|
const { data, done, promise, update, error, id } = suspenseState;
|
||||||
const { hasHydrateData, data: hydrateData } = getHydrateData(id);
|
const { hasHydrateData, data: hydrateData } = getHydrateData(id);
|
||||||
|
|
||||||
|
const queryInProcess = options?.queryKey && queryClient.getQueryData(options.queryKey);
|
||||||
let thenable: Promise<any> = null;
|
let thenable: Promise<any> = null;
|
||||||
if (!hasHydrateData && !error && !done && !promise && request) {
|
if (!hasHydrateData && !error && !done && !promise && request && !queryInProcess) {
|
||||||
thenable = request(requestContext);
|
thenable = request(requestContext);
|
||||||
thenable.then((response) => {
|
thenable.then((response) => {
|
||||||
|
queryClient.removeQueryData(options?.queryKey);
|
||||||
update({
|
update({
|
||||||
done: true,
|
done: true,
|
||||||
data: response,
|
data: response,
|
||||||
promise: null,
|
promise: null,
|
||||||
});
|
});
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
|
queryClient.removeQueryData(options?.queryKey);
|
||||||
update({
|
update({
|
||||||
done: true,
|
done: true,
|
||||||
error: e,
|
error: e,
|
||||||
promise: null,
|
promise: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
queryClient.setQueryData(options?.queryKey, thenable);
|
||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|
@ -117,7 +149,12 @@ export function useSuspenseData(request?: Request) {
|
||||||
promise: thenable,
|
promise: thenable,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
throw thenable;
|
if (thenable) {
|
||||||
|
throw thenable;
|
||||||
|
} else {
|
||||||
|
// Throw a pending promise to Suspense, otherwise the component will be error because of undefined data.
|
||||||
|
throw (queryClient.getQueryData(options?.queryKey) || new Promise(() => {}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SuspenseProps {
|
interface SuspenseProps {
|
||||||
|
|
@ -126,6 +163,11 @@ interface SuspenseProps {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dispatchSuspenseEvent(event: string, id: string) {
|
||||||
|
window.dispatchEvent(new CustomEvent(event, { detail: { id } }));
|
||||||
|
}
|
||||||
|
const DISPATCH_SUSPENSE_EVENT_STRING = dispatchSuspenseEvent.toString();
|
||||||
|
|
||||||
export function withSuspense(Component) {
|
export function withSuspense(Component) {
|
||||||
return (props: SuspenseProps) => {
|
return (props: SuspenseProps) => {
|
||||||
const { fallback, id, ...componentProps } = props;
|
const { fallback, id, ...componentProps } = props;
|
||||||
|
|
@ -153,10 +195,22 @@ export function withSuspense(Component) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Suspense fallback={fallback || null}>
|
<React.Suspense fallback={fallback || null}>
|
||||||
|
<InlineScript
|
||||||
|
id={`suspense-parse-start-${id}`}
|
||||||
|
script={`(${DISPATCH_SUSPENSE_EVENT_STRING})('ice-suspense-parse-start','${id}');`}
|
||||||
|
/>
|
||||||
<SuspenseContext.Provider value={suspenseState}>
|
<SuspenseContext.Provider value={suspenseState}>
|
||||||
<Component {...componentProps} />
|
<Component {...componentProps} />
|
||||||
|
<InlineScript
|
||||||
|
id={`suspense-parse-data-${id}`}
|
||||||
|
script={`(${DISPATCH_SUSPENSE_EVENT_STRING})('ice-suspense-parse-data','${id}');`}
|
||||||
|
/>
|
||||||
<Data id={id} />
|
<Data id={id} />
|
||||||
</SuspenseContext.Provider>
|
</SuspenseContext.Provider>
|
||||||
|
<InlineScript
|
||||||
|
id={`suspense-parse-end-${id}`}
|
||||||
|
script={`(${DISPATCH_SUSPENSE_EVENT_STRING})('ice-suspense-parse-end','${id}');`}
|
||||||
|
/>
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
@ -174,3 +228,20 @@ function Data(props) {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface InlineScriptProps {
|
||||||
|
id: string;
|
||||||
|
script: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function InlineScript(props: InlineScriptProps) {
|
||||||
|
return (
|
||||||
|
<script
|
||||||
|
id={props.id}
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: props.script,
|
||||||
|
}}
|
||||||
|
suppressHydrationWarning
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -2157,10 +2157,10 @@ importers:
|
||||||
version: 1.2.4
|
version: 1.2.4
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@ice/app':
|
'@ice/app':
|
||||||
specifier: ^3.6.3
|
specifier: ^3.6.4
|
||||||
version: link:../ice
|
version: link:../ice
|
||||||
'@ice/runtime':
|
'@ice/runtime':
|
||||||
specifier: ^1.5.4
|
specifier: ^1.5.6
|
||||||
version: link:../runtime
|
version: link:../runtime
|
||||||
webpack:
|
webpack:
|
||||||
specifier: ^5.88.0
|
specifier: ^5.88.0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue