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

Disable <div hidden /> API in old fork, too #18917

Merged
merged 1 commit into from
May 14, 2020
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
8 changes: 6 additions & 2 deletions packages/react-dom/src/__tests__/ReactUpdates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ describe('ReactUpdates', () => {
function LegacyHiddenDiv({hidden, children, ...props}) {
if (gate(flags => flags.new)) {
return (
<div hidden={hidden} {...props}>
<div
hidden={hidden ? 'unstable-do-not-use-legacy-hidden' : false}
{...props}>
<React.unstable_LegacyHidden mode={hidden ? 'hidden' : 'visible'}>
{children}
</React.unstable_LegacyHidden>
</div>
);
} else {
return (
<div hidden={hidden} {...props}>
<div
hidden={hidden ? 'unstable-do-not-use-legacy-hidden' : false}
{...props}>
{children}
</div>
);
Expand Down
10 changes: 9 additions & 1 deletion packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
enableModernEventSystem,
enableCreateEventHandleAPI,
enableScopeAPI,
disableHiddenPropDeprioritization,
} from 'shared/ReactFeatureFlags';
import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
import {TOP_BEFORE_BLUR, TOP_AFTER_BLUR} from '../events/DOMTopLevelEventTypes';
Expand Down Expand Up @@ -372,7 +373,14 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
}

export function shouldDeprioritizeSubtree(type: string, props: Props): boolean {
return !!props.hidden;
if (disableHiddenPropDeprioritization) {
// This is obnoxiously specific so that nobody uses it, but we can still opt
// in via an infra-level userspace abstraction.
return props.hidden === 'unstable-do-not-use-legacy-hidden';
} else {
// Legacy behavior. Any truthy value works.
return !!props.hidden;
}
}

export function createTextInstance(
Expand Down
17 changes: 0 additions & 17 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import {
warnAboutDefaultPropsOnFunctionComponents,
enableScopeAPI,
enableBlocksAPI,
warnAboutDOMHiddenAttribute,
} from 'shared/ReactFeatureFlags';
import invariant from 'shared/invariant';
import shallowEqual from 'shared/shallowEqual';
Expand Down Expand Up @@ -1124,22 +1123,6 @@ function updateHostComponent(
}

markRef(current, workInProgress);

if (__DEV__) {
if (
warnAboutDOMHiddenAttribute &&
(workInProgress.mode & ConcurrentMode) !== NoMode &&
nextProps.hasOwnProperty('hidden')
) {
// This warning will not be user visible. Only exists so React Core team
// can find existing callers and migrate them to the new API.
console.error(
'Detected use of DOM `hidden` attribute. Should migrate to new API. ' +
'(owner: React Core)',
);
}
}

reconcileChildren(current, workInProgress, nextChildren, renderLanes);
return workInProgress.child;
}
Expand Down
16 changes: 0 additions & 16 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import {
warnAboutDefaultPropsOnFunctionComponents,
enableScopeAPI,
enableBlocksAPI,
warnAboutDOMHiddenAttribute,
} from 'shared/ReactFeatureFlags';
import invariant from 'shared/invariant';
import shallowEqual from 'shared/shallowEqual';
Expand Down Expand Up @@ -1100,21 +1099,6 @@ function updateHostComponent(current, workInProgress, renderExpirationTime) {

markRef(current, workInProgress);

if (__DEV__) {
if (
warnAboutDOMHiddenAttribute &&
(workInProgress.mode & ConcurrentMode) !== NoMode &&
nextProps.hasOwnProperty('hidden')
) {
// This warning will not be user visible. Only exists so React Core team
// can find existing callers and migrate them to the new API.
console.error(
'Detected use of DOM `hidden` attribute. Should migrate to new API. ' +
'(owner: React Core)',
);
}
}

// Check the host config to see if the children are offscreen/hidden.
if (
workInProgress.mode & ConcurrentMode &&
Expand Down
8 changes: 6 additions & 2 deletions packages/react-refresh/src/__tests__/ReactFresh-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,19 @@ describe('ReactFresh', () => {
function LegacyHiddenDiv({hidden, children, ...props}) {
if (gate(flags => flags.new)) {
return (
<div hidden={hidden} {...props}>
<div
hidden={hidden ? 'unstable-do-not-use-legacy-hidden' : false}
{...props}>
<React.unstable_LegacyHidden mode={hidden ? 'hidden' : 'visible'}>
{children}
</React.unstable_LegacyHidden>
</div>
);
} else {
return (
<div hidden={hidden} {...props}>
<div
hidden={hidden ? 'unstable-do-not-use-legacy-hidden' : false}
{...props}>
{children}
</div>
);
Expand Down
8 changes: 6 additions & 2 deletions packages/react/src/__tests__/ReactDOMTracing-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ function loadModules() {
function LegacyHiddenDiv({hidden, children, ...props}) {
if (gate(flags => flags.new)) {
return (
<div hidden={hidden} {...props}>
<div
hidden={hidden ? 'unstable-do-not-use-legacy-hidden' : false}
{...props}>
<React.unstable_LegacyHidden mode={hidden ? 'hidden' : 'visible'}>
{children}
</React.unstable_LegacyHidden>
</div>
);
} else {
return (
<div hidden={hidden} {...props}>
<div
hidden={hidden ? 'unstable-do-not-use-legacy-hidden' : false}
{...props}>
{children}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ export const enableLegacyFBSupport = false;
export const deferRenderPhaseUpdateToNextBatch = true;

// Flag used by www build so we can log occurrences of legacy hidden API
export const warnAboutDOMHiddenAttribute = false;
export const disableHiddenPropDeprioritization = true;
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const enableFilterEmptyStringAttributesDOM = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
export const warnAboutDOMHiddenAttribute = false;
export const disableHiddenPropDeprioritization = true;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
export const warnAboutDOMHiddenAttribute = false;
export const disableHiddenPropDeprioritization = true;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
export const warnAboutDOMHiddenAttribute = false;
export const disableHiddenPropDeprioritization = true;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
export const warnAboutDOMHiddenAttribute = false;
export const disableHiddenPropDeprioritization = true;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
export const warnAboutDOMHiddenAttribute = false;
export const disableHiddenPropDeprioritization = true;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.testing.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;

export const enableNewReconciler = false;
export const deferRenderPhaseUpdateToNextBatch = true;
export const warnAboutDOMHiddenAttribute = false;
export const disableHiddenPropDeprioritization = true;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
Expand Down
10 changes: 3 additions & 7 deletions packages/shared/forks/ReactFeatureFlags.www-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export const enableModernEventSystem = __VARIANT__;
export const enableLegacyFBSupport = __VARIANT__;
export const enableDebugTracing = !__VARIANT__;

// Temporary flag, in case we need to re-enable this feature.
export const disableHiddenPropDeprioritization = __VARIANT__;

// This only has an effect in the new reconciler. But also, the new reconciler
// is only enabled when __VARIANT__ is true. So this is set to the opposite of
// __VARIANT__ so that it's `false` when running against the new reconciler.
Expand All @@ -36,13 +39,6 @@ export const deferRenderPhaseUpdateToNextBatch = !__VARIANT__;
export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;

// Do not add the corresponding warning to the warning filter! Only exists so we
// can detect callers and migrate them to the new API. Should not visible to
// anyone outside React Core team.
//
// Disabled in our tests, but we'll enable in www.
export const warnAboutDOMHiddenAttribute = false;

// TODO: These flags are hard-coded to the default values used in open source.
// Update the tests so that they pass in either mode, then set these
// to __VARIANT__.
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const {
enableLegacyFBSupport,
enableDebugTracing,
deferRenderPhaseUpdateToNextBatch,
warnAboutDOMHiddenAttribute,
disableHiddenPropDeprioritization,
} = dynamicFeatureFlags;

// On WWW, __EXPERIMENTAL__ is used for a new modern build.
Expand Down