Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unstable_changedBits #20953

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-cache/src/ReactCacheOld.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ReactCurrentDispatcher =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.ReactCurrentDispatcher;

function readContext(Context, observedBits) {
function readContext(Context) {
const dispatcher = ReactCurrentDispatcher.current;
if (dispatcher === null) {
throw new Error(
Expand All @@ -55,7 +55,7 @@ function readContext(Context, observedBits) {
'lifecycle methods.',
);
}
return dispatcher.readContext(Context, observedBits);
return dispatcher.readContext(Context);
}

function identityHashFn(input) {
Expand Down
10 changes: 2 additions & 8 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,12 @@ function getCacheForType<T>(resourceType: () => T): T {
invariant(false, 'Not implemented.');
}

function readContext<T>(
context: ReactContext<T>,
observedBits: void | number | boolean,
): T {
function readContext<T>(context: ReactContext<T>): T {
// For now we don't expose readContext usage in the hooks debugging info.
return context._currentValue;
}

function useContext<T>(
context: ReactContext<T>,
observedBits: void | number | boolean,
): T {
function useContext<T>(context: ReactContext<T>): T {
hookLog.push({
primitive: 'Context',
stackError: new Error(),
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/src/devtools/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Rejected = 2;
const ReactCurrentDispatcher = (React: any)
.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher;

function readContext(Context, observedBits) {
function readContext(Context) {
const dispatcher = ReactCurrentDispatcher.current;
if (dispatcher === null) {
throw new Error(
Expand All @@ -70,7 +70,7 @@ function readContext(Context, observedBits) {
'lifecycle methods.',
);
}
return dispatcher.readContext(Context, observedBits);
return dispatcher.readContext(Context);
}

const CacheContext = createContext(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,6 @@ describe('ReactDOMServerHooks', () => {
},
);

itRenders('warns when bitmask is passed to useContext', async render => {
const Context = React.createContext('Hi');

function Foo() {
return <span>{useContext(Context, 1)}</span>;
}

const domNode = await render(<Foo />, 1);
expect(domNode.textContent).toBe('Hi');
});

describe('useDebugValue', () => {
itRenders('is a noop', async render => {
function Counter(props) {
Expand All @@ -760,11 +749,11 @@ describe('ReactDOMServerHooks', () => {
});

describe('readContext', () => {
function readContext(Context, observedBits) {
function readContext(Context) {
const dispatcher =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.ReactCurrentDispatcher.current;
return dispatcher.readContext(Context, observedBits);
return dispatcher.readContext(Context);
}

itRenders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ describe('ReactDOMServerIntegration', () => {
});

itRenders('readContext() in different components', async render => {
function readContext(Ctx, observedBits) {
function readContext(Ctx) {
const dispatcher =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.ReactCurrentDispatcher.current;
return dispatcher.readContext(Ctx, observedBits);
return dispatcher.readContext(Ctx);
}

class Cls extends React.Component {
Expand Down
10 changes: 2 additions & 8 deletions packages/react-dom/src/server/ReactPartialRendererHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,7 @@ function getCacheForType<T>(resourceType: () => T): T {
invariant(false, 'Not implemented.');
}

function readContext<T>(
context: ReactContext<T>,
observedBits: void | number | boolean,
): T {
function readContext<T>(context: ReactContext<T>): T {
const threadID = currentPartialRenderer.threadID;
validateContextBounds(context, threadID);
if (__DEV__) {
Expand All @@ -238,10 +235,7 @@ function readContext<T>(
return context[threadID];
}

function useContext<T>(
context: ReactContext<T>,
observedBits: void | number | boolean,
): T {
function useContext<T>(context: ReactContext<T>): T {
if (__DEV__) {
currentHookNameInDev = 'useContext';
}
Expand Down
29 changes: 6 additions & 23 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ import {
checkIfContextChanged,
readContext,
prepareToReadContext,
calculateChangedBits,
scheduleWorkOnParentPath,
} from './ReactFiberNewContext.new';
import {renderWithHooks, bailoutHooks} from './ReactFiberHooks.new';
Expand Down Expand Up @@ -221,7 +220,7 @@ import {
restoreSpawnedCachePool,
getOffscreenDeferredCachePool,
} from './ReactFiberCacheComponent.new';
import {MAX_SIGNED_31_BIT_INT} from './MaxInts';
import is from 'shared/objectIs';

import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';

Expand Down Expand Up @@ -796,12 +795,7 @@ function updateCacheComponent(
pushCacheProvider(workInProgress, nextCache);
if (nextCache !== prevState.cache) {
// This cache refreshed. Propagate a context change.
propagateContextChange(
workInProgress,
CacheContext,
MAX_SIGNED_31_BIT_INT,
renderLanes,
);
propagateContextChange(workInProgress, CacheContext, renderLanes);
}
}
}
Expand Down Expand Up @@ -1168,12 +1162,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {
pushCacheProvider(workInProgress, nextCache);
if (nextCache !== prevState.cache) {
// The root cache refreshed.
propagateContextChange(
workInProgress,
CacheContext,
MAX_SIGNED_31_BIT_INT,
renderLanes,
);
propagateContextChange(workInProgress, CacheContext, renderLanes);
}
}

Expand Down Expand Up @@ -3007,8 +2996,7 @@ function updateContextProvider(
} else {
if (oldProps !== null) {
const oldValue = oldProps.value;
const changedBits = calculateChangedBits(context, newValue, oldValue);
if (changedBits === 0) {
if (is(oldValue, newValue)) {
// No change. Bailout early if children are the same.
if (
oldProps.children === newProps.children &&
Expand All @@ -3023,12 +3011,7 @@ function updateContextProvider(
} else {
// The context value changed. Search for matching consumers and schedule
// them to update.
propagateContextChange(
workInProgress,
context,
changedBits,
renderLanes,
);
propagateContextChange(workInProgress, context, renderLanes);
}
}
}
Expand Down Expand Up @@ -3086,7 +3069,7 @@ function updateContextConsumer(
}

prepareToReadContext(workInProgress, renderLanes);
const newValue = readContext(context, newProps.unstable_observedBits);
const newValue = readContext(context);
let newChildren;
if (__DEV__) {
ReactCurrentOwner.current = workInProgress;
Expand Down
29 changes: 6 additions & 23 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ import {
checkIfContextChanged,
readContext,
prepareToReadContext,
calculateChangedBits,
scheduleWorkOnParentPath,
} from './ReactFiberNewContext.old';
import {renderWithHooks, bailoutHooks} from './ReactFiberHooks.old';
Expand Down Expand Up @@ -221,7 +220,7 @@ import {
restoreSpawnedCachePool,
getOffscreenDeferredCachePool,
} from './ReactFiberCacheComponent.old';
import {MAX_SIGNED_31_BIT_INT} from './MaxInts';
import is from 'shared/objectIs';

import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';

Expand Down Expand Up @@ -796,12 +795,7 @@ function updateCacheComponent(
pushCacheProvider(workInProgress, nextCache);
if (nextCache !== prevState.cache) {
// This cache refreshed. Propagate a context change.
propagateContextChange(
workInProgress,
CacheContext,
MAX_SIGNED_31_BIT_INT,
renderLanes,
);
propagateContextChange(workInProgress, CacheContext, renderLanes);
}
}
}
Expand Down Expand Up @@ -1168,12 +1162,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {
pushCacheProvider(workInProgress, nextCache);
if (nextCache !== prevState.cache) {
// The root cache refreshed.
propagateContextChange(
workInProgress,
CacheContext,
MAX_SIGNED_31_BIT_INT,
renderLanes,
);
propagateContextChange(workInProgress, CacheContext, renderLanes);
}
}

Expand Down Expand Up @@ -3007,8 +2996,7 @@ function updateContextProvider(
} else {
if (oldProps !== null) {
const oldValue = oldProps.value;
const changedBits = calculateChangedBits(context, newValue, oldValue);
if (changedBits === 0) {
if (is(oldValue, newValue)) {
// No change. Bailout early if children are the same.
if (
oldProps.children === newProps.children &&
Expand All @@ -3023,12 +3011,7 @@ function updateContextProvider(
} else {
// The context value changed. Search for matching consumers and schedule
// them to update.
propagateContextChange(
workInProgress,
context,
changedBits,
renderLanes,
);
propagateContextChange(workInProgress, context, renderLanes);
}
}
}
Expand Down Expand Up @@ -3086,7 +3069,7 @@ function updateContextConsumer(
}

prepareToReadContext(workInProgress, renderLanes);
const newValue = readContext(context, newProps.unstable_observedBits);
const newValue = readContext(context);
let newChildren;
if (__DEV__) {
ReactCurrentOwner.current = workInProgress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const CacheContext: ReactContext<Cache> = enableCache
// We don't use Consumer/Provider for Cache components. So we'll cheat.
Consumer: (null: any),
Provider: (null: any),
_calculateChangedBits: null,
// We'll initialize these at the root.
_currentValue: (null: any),
_currentValue2: (null: any),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const CacheContext: ReactContext<Cache> = enableCache
// We don't use Consumer/Provider for Cache components. So we'll cheat.
Consumer: (null: any),
Provider: (null: any),
_calculateChangedBits: null,
// We'll initialize these at the root.
_currentValue: (null: any),
_currentValue2: (null: any),
Expand Down
Loading