fix: react dupes

This commit is contained in:
cha0s 2020-12-22 11:39:22 -06:00
parent a2b558a9ec
commit fee67bbbd6
4 changed files with 41 additions and 22 deletions

View File

@ -6,3 +6,12 @@ const clientMains = [
];
module.exports = splitConfig(pkg, clientMains);
module.exports[1].use.push((neutrino) => {
neutrino.config.merge({
externals: {
react: 'react',
'react-dom': 'react-dom',
},
});
});

View File

@ -8,20 +8,26 @@ export {LatusContext, React};
export default {
hooks: {
'@latus/http/client/up': async (latus) => {
const Components = latus.invoke('@latus/react/client/components');
const Providers = await latus.invokeOrdered('@latus/react/client/providers');
const children = await Promise.all(
Object.entries(Components)
.map(async ([key, Component]) => React.createElement(await Component, {key})),
const Components = Object.fromEntries(
await Promise.all(
Object.entries(latus.invoke('@latus/react/client/components'))
.map(async ([key, Component]) => [key, await Component]),
),
);
const RootElement = [
[LatusContext.Provider, {value: latus}],
].concat(Providers)
.reverse()
.reduce((children, [Provider, props], i) => [
React.createElement(Provider, {key: `@latus/react/provider(${i})`, ...props}, children),
], children);
return render(RootElement[0], window.document.getElementById('root'));
const Providers = await latus.invokeOrdered('@latus/react/client/providers');
const RootComponent = () => {
const children = Object.entries(Components)
.map(([key, Component]) => React.createElement(Component, {key}));
const RootElements = [
[LatusContext.Provider, {value: latus}],
].concat(Providers)
.reverse()
.reduce((children, [Provider, props], i) => [
React.createElement(Provider, {key: `@latus/react/provider(${i})`, ...props}, children),
], children);
return RootElements[0];
};
return render(React.createElement(RootComponent), window.document.getElementById('root'));
},
},
};

View File

@ -27,8 +27,6 @@
"debug": "4.3.1",
"deepmerge": "^4.2.2",
"lodash.throttle": "^4.1.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-redux": "^7.2.2",
"reduce-reducers": "^1.0.4",
"redux": "^4.0.5"
@ -43,7 +41,13 @@
"eslint-import-resolver-webpack": "0.13.0",
"mocha": "^8",
"neutrino": "^9.4.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"webpack": "^4",
"webpack-cli": "^3"
},
"peerDependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1"
}
}

View File

@ -910,10 +910,10 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"
"@latus/core@^1.0.0":
version "1.0.0"
resolved "https://npm.i12e.cha0s.io/@latus%2fcore/-/core-1.0.0.tgz#6fd2990a8bf8069bd331238141496a4230c4a5db"
integrity sha512-sf0g1ZhvqwbHcQVL9ivV+6QWcKu4o69aDSOV/vp/zalBT1C7yDxvbNuwNkNP5GZZI2knd7oRiA1KAd3Z4e18rg==
"@latus/core@^2.0.0":
version "2.0.0"
resolved "https://npm.i12e.cha0s.io/@latus%2fcore/-/core-2.0.0.tgz#865c5eac67720d39867cee6340dcca18fa556791"
integrity sha512-4w0zmXOfCOPsDVopXOr8x2P4urvlTK1gYdCq5Jo4vtmyQgqZj5FjBC+PliPnyxppoRc9nM5AAX4604o34CXXQg==
dependencies:
debug "4.3.1"
js-yaml "3.14.0"
@ -2463,9 +2463,9 @@ duplexify@^3.4.2, duplexify@^3.6.0:
stream-shift "^1.0.0"
electron-to-chromium@^1.3.621:
version "1.3.629"
resolved "https://npm.i12e.cha0s.io/electron-to-chromium/-/electron-to-chromium-1.3.629.tgz#a08d13b64d90e3c77ec5b9bffa3efbc5b4a00969"
integrity sha512-iSPPJtPvHrMAvYOt+9cdbDmTasPqwnwz4lkP8Dn200gDNUBQOLQ96xUsWXBwXslAo5XxdoXAoQQ3RAy4uao9IQ==
version "1.3.631"
resolved "https://npm.i12e.cha0s.io/electron-to-chromium/-/electron-to-chromium-1.3.631.tgz#b28ebc7bfb348bb0aede2fae8888d775ddb6f5ee"
integrity sha512-mPEG/52142po0XK1jQkZtbMmp38MZtQ3JDFItYxV65WXyhxDYEQ54tP4rb93m0RbMlZqQ+4zBw2N7UumSgGfbA==
elliptic@^6.5.3:
version "6.5.3"