Skip to content

Commit

Permalink
Resolve cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Apr 23, 2024
1 parent 197914e commit fac727f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/react-dom/src/client/ReactDOMRootFB.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import {LegacyRoot} from 'react-reconciler/src/ReactRootTags';
import getComponentNameFromType from 'shared/getComponentNameFromType';
import {has as hasInstance} from 'shared/ReactInstanceMap';

import {currentOwner} from 'react-reconciler/src/ReactFiberAsyncDispatcher';
import {currentOwner} from 'react-reconciler/src/ReactFiberCurrentOwner';

import assign from 'shared/assign';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from 'react-reconciler/src/ReactFiberReconciler';
import {doesFiberContain} from 'react-reconciler/src/ReactFiberTreeReflection';
import getComponentNameFromType from 'shared/getComponentNameFromType';
import {currentOwner} from 'react-reconciler/src/ReactFiberAsyncDispatcher';
import {currentOwner} from 'react-reconciler/src/ReactFiberCurrentOwner';

export function findHostInstance_DEPRECATED<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
Expand Down
8 changes: 2 additions & 6 deletions packages/react-reconciler/src/ReactFiberAsyncDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {CacheContext} from './ReactFiberCacheComponent';

import {disableStringRefs} from 'shared/ReactFeatureFlags';

import {currentOwner} from './ReactFiberCurrentOwner';

function getCacheForType<T>(resourceType: () => T): T {
if (!enableCache) {
throw new Error('Not implemented.');
Expand All @@ -29,8 +31,6 @@ function getCacheForType<T>(resourceType: () => T): T {
return cacheForType;
}

export let currentOwner: Fiber | null = null;

export const DefaultAsyncDispatcher: AsyncDispatcher = ({
getCacheForType,
}: any);
Expand All @@ -40,7 +40,3 @@ if (__DEV__ || !disableStringRefs) {
return currentOwner;
};
}

export function setCurrentOwner(fiber: null | Fiber) {
currentOwner = fiber;
}
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ import {
pushRootMarkerInstance,
TransitionTracingMarker,
} from './ReactFiberTracingMarkerComponent';
import {setCurrentOwner} from './ReactFiberAsyncDispatcher';
import {setCurrentOwner} from './ReactFiberCurrentOwner';

// A special exception that's used to unwind the stack when an update flows
// into a dehydrated boundary.
Expand Down
16 changes: 16 additions & 0 deletions packages/react-reconciler/src/ReactFiberCurrentOwner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {Fiber} from './ReactInternalTypes';

export let currentOwner: Fiber | null = null;

export function setCurrentOwner(fiber: null | Fiber) {
currentOwner = fiber;
}
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberTreeReflection.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
SuspenseComponent,
} from './ReactWorkTags';
import {NoFlags, Placement, Hydrating} from './ReactFiberFlags';
import {currentOwner} from './ReactFiberAsyncDispatcher';
import {currentOwner} from './ReactFiberCurrentOwner';

export function getNearestMountedFiber(fiber: Fiber): null | Fiber {
let node = fiber;
Expand Down
6 changes: 2 additions & 4 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ import {
resetHooksOnUnwind,
ContextOnlyDispatcher,
} from './ReactFiberHooks';
import {
DefaultAsyncDispatcher,
setCurrentOwner,
} from './ReactFiberAsyncDispatcher';
import {DefaultAsyncDispatcher} from './ReactFiberAsyncDispatcher';
import {setCurrentOwner} from './ReactFiberCurrentOwner';
import {
createCapturedValueAtFiber,
type CapturedValue,
Expand Down

0 comments on commit fac727f

Please sign in to comment.