From 8758f303d2709465a8a2c4bf407a0e99cac8841c Mon Sep 17 00:00:00 2001 From: Malash Date: Thu, 12 Dec 2024 15:19:06 +0800 Subject: [PATCH] remove Partial component --- packages/core/src/components/index.tsx | 5 +- packages/core/src/index.ts | 1 - packages/core/src/partial/index.tsx | 83 -------------------------- yarn.lock | 10 +--- 4 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 packages/core/src/partial/index.tsx diff --git a/packages/core/src/components/index.tsx b/packages/core/src/components/index.tsx index 9ede212a..15272e9d 100644 --- a/packages/core/src/components/index.tsx +++ b/packages/core/src/components/index.tsx @@ -3,7 +3,6 @@ import { UniversalHooksProvider } from '../lifecycles/universal/provider'; import { PortalProvider } from '../portal'; import { Container } from '../container'; import { ContainerProvider } from './container'; -import { PartialProvider } from '../partial'; export const GojiProvider = ({ children, @@ -13,9 +12,7 @@ export const GojiProvider = ({ }>) => ( - - {children} - + {children} ); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 21069ccd..1bd2c640 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -45,7 +45,6 @@ export { getTemplateIds as unstable_getTemplateIds, } from './constants'; export { gojiEvents } from './events'; -export { Partial } from './partial'; // eslint-disable-next-line camelcase export { batchedUpdates as unstable_batchedUpdates }; export { PublicInstance as GojiPublicInstance } from './reconciler/publicInstance'; diff --git a/packages/core/src/partial/index.tsx b/packages/core/src/partial/index.tsx deleted file mode 100644 index 7240c84c..00000000 --- a/packages/core/src/partial/index.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import React, { createContext, useRef, useContext, Suspense, useEffect, ReactElement } from 'react'; -import { useRenderedEffect } from '../lifecycles'; - -// PartialContext maintains a promise chain to control the render order -const createPartialContextValue = () => { - let chain: Promise = Promise.resolve(); - - // register will create a promise and link it to the promise chain, - // then return its predecessor and the resolver of the new created promise. - const register = () => { - let resolver; - const currentPromise = chain; - const nextPromise = new Promise(resolve => { - resolver = () => resolve(undefined); - }); - - chain = chain.then(() => nextPromise); - - return [currentPromise, resolver]; - }; - - return { - register, - }; -}; - -const PartialContext = createContext(createPartialContextValue()); - -export const PartialProvider = ({ children }) => ( - - {children} - - ); - -// Let's imagine there are only two Partial Components on the page, -// the first component will throw the very first promise in the chain which is already resolved, -// meanwhile the second component will throw the second promise which is chained after the first promise, -// since the first promise is resolved, first component will start rendering children, -// when its children are rendered (useRenderedEffect), first component will call the resolver of the second promise, -// then the second compnent will start rendering children. -const DelayComp = ({ children, promise, resolver }) => { - if (promise.current !== null && resolver.current) { - throw promise.current; - } - - useRenderedEffect(() => { - if (resolver.current) { - resolver.current(); - resolver.current = null; - } - }, [promise.current]); // eslint-disable-line react-hooks/exhaustive-deps - - return children; -}; - -export const Partial = ({ - children, - fallback, -}: React.PropsWithChildren<{ fallback?: ReactElement }>) => { - const pending = useRef(true); - const { register } = useContext(PartialContext); - const resolverRef = useRef(null); - const promiseRef = useRef(null); - - if (pending.current) { - const [promise, resolver] = register(); - resolverRef.current = resolver; - promiseRef.current = promise; - } - - useEffect(() => { - pending.current = false; - promiseRef.current = null; - }, []); - - return ( - - - {children} - - - ); -}; diff --git a/yarn.lock b/yarn.lock index 661ccb7b..7443ebed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2857,7 +2857,7 @@ "@docusaurus/theme-search-algolia" "2.4.3" "@docusaurus/types" "2.4.3" -"@docusaurus/react-loadable@5.5.2": +"@docusaurus/react-loadable@5.5.2", "react-loadable@npm:@docusaurus/react-loadable@5.5.2": version "5.5.2" resolved "https://registry.yarnpkg.com/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz#81aae0db81ecafbdaee3651f12804580868fa6ce" integrity sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ== @@ -14296,14 +14296,6 @@ react-loadable-ssr-addon-v5-slorber@^1.0.1: dependencies: "@babel/runtime" "^7.10.3" -"react-loadable@npm:@docusaurus/react-loadable@5.5.2": - version "5.5.2" - resolved "https://registry.yarnpkg.com/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz#81aae0db81ecafbdaee3651f12804580868fa6ce" - integrity sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ== - dependencies: - "@types/react" "*" - prop-types "^15.6.2" - react-reconciler@^0.26.2: version "0.26.2" resolved "https://registry.yarnpkg.com/react-reconciler/-/react-reconciler-0.26.2.tgz#bbad0e2d1309423f76cf3c3309ac6c96e05e9d91"