mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-23 14:39:32 +08:00
Merge pull request #350 from lowdefy/context-render-bug
fix(renderer): Fix context creation render loop bug.
This commit is contained in:
commit
c334e271d3
@ -21,10 +21,8 @@ import getContext from '@lowdefy/engine';
|
|||||||
|
|
||||||
import OnEnter from './OnEnter';
|
import OnEnter from './OnEnter';
|
||||||
|
|
||||||
const contexts = {};
|
|
||||||
|
|
||||||
const Context = ({ block, contextId, pageId, render, rootContext }) => {
|
const Context = ({ block, contextId, pageId, render, rootContext }) => {
|
||||||
const [loading, setLoading] = useState(true);
|
const [context, setContext] = useState({});
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -38,8 +36,7 @@ const Context = ({ block, contextId, pageId, render, rootContext }) => {
|
|||||||
rootContext,
|
rootContext,
|
||||||
});
|
});
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
contexts[contextId] = ctx;
|
setContext(ctx);
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err);
|
setError(err);
|
||||||
@ -51,7 +48,7 @@ const Context = ({ block, contextId, pageId, render, rootContext }) => {
|
|||||||
};
|
};
|
||||||
}, [block, pageId, rootContext, contextId]);
|
}, [block, pageId, rootContext, contextId]);
|
||||||
|
|
||||||
if (loading)
|
if (context.id !== contextId)
|
||||||
return (
|
return (
|
||||||
<Loading
|
<Loading
|
||||||
properties={get(block, 'meta.loading.properties')}
|
properties={get(block, 'meta.loading.properties')}
|
||||||
@ -61,7 +58,7 @@ const Context = ({ block, contextId, pageId, render, rootContext }) => {
|
|||||||
|
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
|
|
||||||
return <OnEnter block={block} context={contexts[contextId]} render={render} />;
|
return <OnEnter block={block} context={context} render={render} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Context;
|
export default Context;
|
||||||
|
Loading…
Reference in New Issue
Block a user