react/src/renderers/shared/fiber/ReactDebugCurrentFiber.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

[Fiber] Fix some of the warnings (#8570) * Implement component stack for some warnings in Fiber * Keep Fiber debug source up to date When an element changes, we should copy the source and owner again. Otherwise they can get stale since we're not reading them from the element. * Remove outdated TODOs from tests * Explicitly specify Fiber types to include in the stack Fixes an accidental omission when both source and owner are null but displayName exists. * Fix mised Stack+Fiber test to not expect extra warnings When we're in Fiber mode we don't actually expect that warning being printed. * Warn on passing different props to super() * Implement duplicate key warnings We keep known keys in a set in development. There is an annoying special case where we know we'll check it again because we break out of the loop early. One test in the tree hook regresses to the failing state because it checks that the tree hook works without a Set available, but we started using Set in this code. It is not essential and we can clean this up later when we decide how to deal with polyfills. * Move ReactTypeOfWork to src/shared It needs to be available both to Fiber and Isomorphic because the tree hook lives in Isomorphic but pretty-prints Fiber stack. * Add dev-only ReactDebugCurrentFiber for warnings The goal is to use ReactCurrentOwner less and rely on ReactDebugCurrentFiber for warning owner name and stack. * Make Stack invariant messages more consistent Fiber used a helper so two tests had the same phrasing. Stack also used a helper for most invariants but hardcoded a different phrase in one place. I changed that invariant message to use a helper which made it consistent with what it prints in Fiber. * Make CSSPropertyOperations use getCurrentFiberOwnerName() This gets mount-time CSS warnings to be printed. However update-time warnings are currently ignored because current fiber is not yet available during the commit phase. We also regress on HostOperation hook tests but this doesn't matter because it's only used by ReactPerf and it doesn't work with Fiber yet anyway. We'll have to think more about it later. * Set ReactDebugCurrentFiber during the commit phase This makes it available during updates, fixing the last failing test in CSSPropertyOperations. * Add DOM warnings by calling hooks directly It is not clear if the old hook system is worth it in its generic incarnation. For now I am just hooking it up to the DOMFiber renderer directly. * Add client-side counterparts for some warning tests This helps us track which warnings are really failing in Fiber, and which ones depend on SSR.
2016-12-16 00:36:58 +08:00
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactDebugCurrentFiber
* @flow
*/
'use strict';
import type { Fiber } from 'ReactFiber';
if (__DEV__) {
var getComponentName = require('getComponentName');
var { getStackAddendumByWorkInProgressFiber } = require('ReactComponentTreeHook');
}
function getCurrentFiberOwnerName() : string | null {
if (__DEV__) {
const fiber = ReactDebugCurrentFiber.current;
if (fiber === null) {
[Fiber] Fix some of the warnings (#8570) * Implement component stack for some warnings in Fiber * Keep Fiber debug source up to date When an element changes, we should copy the source and owner again. Otherwise they can get stale since we're not reading them from the element. * Remove outdated TODOs from tests * Explicitly specify Fiber types to include in the stack Fixes an accidental omission when both source and owner are null but displayName exists. * Fix mised Stack+Fiber test to not expect extra warnings When we're in Fiber mode we don't actually expect that warning being printed. * Warn on passing different props to super() * Implement duplicate key warnings We keep known keys in a set in development. There is an annoying special case where we know we'll check it again because we break out of the loop early. One test in the tree hook regresses to the failing state because it checks that the tree hook works without a Set available, but we started using Set in this code. It is not essential and we can clean this up later when we decide how to deal with polyfills. * Move ReactTypeOfWork to src/shared It needs to be available both to Fiber and Isomorphic because the tree hook lives in Isomorphic but pretty-prints Fiber stack. * Add dev-only ReactDebugCurrentFiber for warnings The goal is to use ReactCurrentOwner less and rely on ReactDebugCurrentFiber for warning owner name and stack. * Make Stack invariant messages more consistent Fiber used a helper so two tests had the same phrasing. Stack also used a helper for most invariants but hardcoded a different phrase in one place. I changed that invariant message to use a helper which made it consistent with what it prints in Fiber. * Make CSSPropertyOperations use getCurrentFiberOwnerName() This gets mount-time CSS warnings to be printed. However update-time warnings are currently ignored because current fiber is not yet available during the commit phase. We also regress on HostOperation hook tests but this doesn't matter because it's only used by ReactPerf and it doesn't work with Fiber yet anyway. We'll have to think more about it later. * Set ReactDebugCurrentFiber during the commit phase This makes it available during updates, fixing the last failing test in CSSPropertyOperations. * Add DOM warnings by calling hooks directly It is not clear if the old hook system is worth it in its generic incarnation. For now I am just hooking it up to the DOMFiber renderer directly. * Add client-side counterparts for some warning tests This helps us track which warnings are really failing in Fiber, and which ones depend on SSR.
2016-12-16 00:36:58 +08:00
return null;
}
Warn for callback refs on functional components (Stack + Fiber) (#8635) * Fiber: warn for refs on SFCs * Stateless refs: update warning to use component stack * Warn for function refs (stack and fiber) * Add owner reference to ref warnings * Centralize stack ref warnings in ReactRef.attachRef * Fiber stateless comp ref warning should only do work when necessary * ReactDebugCurrentFiber maybe FunctionalComponents should act this way instead * (chore) scripts/fiber/record-tests * Add component._compositeType to ReactInstance Flow definition * Don't handle 'stack inside fiber' case in the warning We don't have a test for it. It's easy to mess it up and print the wrong thing so instead of verifying it I'll just remove this bit. * Revert the change to getCurrentFiberOwnerName This happened to work, but it is just a coincidence. This change didn’t really match what the function was supposed to be doing. I’m not sure what the correct fix would be yet so this commit breaks tests. * Add component indirection to the tests using owner name This passes in Stack. It helps ensure we supply the correct owner name. * Invalid type invariant should read owner from element This brings the Fiber behavior in line with how Stack does it. The Fiber test was passing accidentally but broke down in more complicated cases (such as when we have an <Indirection> between the owner and the failing element). Now we can also remove the weird cases from getCurrentFiberOwnerName() that didn't really make sense but helped get the (incomplete) tests pass in the past. * Fiber should throw on a string ref inside functional component
2017-01-10 07:09:18 +08:00
if (fiber._debugOwner != null) {
return getComponentName(fiber._debugOwner);
[Fiber] Fix some of the warnings (#8570) * Implement component stack for some warnings in Fiber * Keep Fiber debug source up to date When an element changes, we should copy the source and owner again. Otherwise they can get stale since we're not reading them from the element. * Remove outdated TODOs from tests * Explicitly specify Fiber types to include in the stack Fixes an accidental omission when both source and owner are null but displayName exists. * Fix mised Stack+Fiber test to not expect extra warnings When we're in Fiber mode we don't actually expect that warning being printed. * Warn on passing different props to super() * Implement duplicate key warnings We keep known keys in a set in development. There is an annoying special case where we know we'll check it again because we break out of the loop early. One test in the tree hook regresses to the failing state because it checks that the tree hook works without a Set available, but we started using Set in this code. It is not essential and we can clean this up later when we decide how to deal with polyfills. * Move ReactTypeOfWork to src/shared It needs to be available both to Fiber and Isomorphic because the tree hook lives in Isomorphic but pretty-prints Fiber stack. * Add dev-only ReactDebugCurrentFiber for warnings The goal is to use ReactCurrentOwner less and rely on ReactDebugCurrentFiber for warning owner name and stack. * Make Stack invariant messages more consistent Fiber used a helper so two tests had the same phrasing. Stack also used a helper for most invariants but hardcoded a different phrase in one place. I changed that invariant message to use a helper which made it consistent with what it prints in Fiber. * Make CSSPropertyOperations use getCurrentFiberOwnerName() This gets mount-time CSS warnings to be printed. However update-time warnings are currently ignored because current fiber is not yet available during the commit phase. We also regress on HostOperation hook tests but this doesn't matter because it's only used by ReactPerf and it doesn't work with Fiber yet anyway. We'll have to think more about it later. * Set ReactDebugCurrentFiber during the commit phase This makes it available during updates, fixing the last failing test in CSSPropertyOperations. * Add DOM warnings by calling hooks directly It is not clear if the old hook system is worth it in its generic incarnation. For now I am just hooking it up to the DOMFiber renderer directly. * Add client-side counterparts for some warning tests This helps us track which warnings are really failing in Fiber, and which ones depend on SSR.
2016-12-16 00:36:58 +08:00
}
}
return null;
}
function getCurrentFiberStackAddendum() : string | null {
if (__DEV__) {
const fiber = ReactDebugCurrentFiber.current;
if (fiber === null) {
[Fiber] Fix some of the warnings (#8570) * Implement component stack for some warnings in Fiber * Keep Fiber debug source up to date When an element changes, we should copy the source and owner again. Otherwise they can get stale since we're not reading them from the element. * Remove outdated TODOs from tests * Explicitly specify Fiber types to include in the stack Fixes an accidental omission when both source and owner are null but displayName exists. * Fix mised Stack+Fiber test to not expect extra warnings When we're in Fiber mode we don't actually expect that warning being printed. * Warn on passing different props to super() * Implement duplicate key warnings We keep known keys in a set in development. There is an annoying special case where we know we'll check it again because we break out of the loop early. One test in the tree hook regresses to the failing state because it checks that the tree hook works without a Set available, but we started using Set in this code. It is not essential and we can clean this up later when we decide how to deal with polyfills. * Move ReactTypeOfWork to src/shared It needs to be available both to Fiber and Isomorphic because the tree hook lives in Isomorphic but pretty-prints Fiber stack. * Add dev-only ReactDebugCurrentFiber for warnings The goal is to use ReactCurrentOwner less and rely on ReactDebugCurrentFiber for warning owner name and stack. * Make Stack invariant messages more consistent Fiber used a helper so two tests had the same phrasing. Stack also used a helper for most invariants but hardcoded a different phrase in one place. I changed that invariant message to use a helper which made it consistent with what it prints in Fiber. * Make CSSPropertyOperations use getCurrentFiberOwnerName() This gets mount-time CSS warnings to be printed. However update-time warnings are currently ignored because current fiber is not yet available during the commit phase. We also regress on HostOperation hook tests but this doesn't matter because it's only used by ReactPerf and it doesn't work with Fiber yet anyway. We'll have to think more about it later. * Set ReactDebugCurrentFiber during the commit phase This makes it available during updates, fixing the last failing test in CSSPropertyOperations. * Add DOM warnings by calling hooks directly It is not clear if the old hook system is worth it in its generic incarnation. For now I am just hooking it up to the DOMFiber renderer directly. * Add client-side counterparts for some warning tests This helps us track which warnings are really failing in Fiber, and which ones depend on SSR.
2016-12-16 00:36:58 +08:00
return null;
}
// Safe because if current fiber exists, we are reconciling,
// and it is guaranteed to be the work-in-progress version.
return getStackAddendumByWorkInProgressFiber(fiber);
}
return null;
}
var ReactDebugCurrentFiber = {
current: (null : Fiber | null),
getCurrentFiberOwnerName,
getCurrentFiberStackAddendum,
};
module.exports = ReactDebugCurrentFiber;