Skip to content

Commit a7860c6

Browse files
committed
Render warning: allow ignoring for a specific component
Add a @:ignoreReRender meta to a component to avoid warnings about avoidable re-renders of this component. False positives may happen when child components rely on context (legacy API) to update themselves.
1 parent 914ad32 commit a7860c6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/lib/react/ReactDebugMacro.hx

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import haxe.macro.TypeTools;
99

1010
class ReactDebugMacro
1111
{
12+
public static inline var IGNORE_RERENDER_META = ':ignoreReRender';
1213
public static var firstRenderWarning:Bool = true;
1314

1415
#if macro
@@ -32,8 +33,9 @@ class ReactDebugMacro
3233
default:
3334
}
3435

35-
if (!updateComponentUpdate(fields, inClass, propsType, stateType))
36-
addComponentUpdate(fields, inClass, propsType, stateType);
36+
if (!inClass.meta.has(IGNORE_RERENDER_META))
37+
if (!updateComponentUpdate(fields, inClass, propsType, stateType))
38+
addComponentUpdate(fields, inClass, propsType, stateType);
3739

3840
if (hasState && !updateConstructor(fields, inClass, propsType, stateType))
3941
addConstructor(fields, inClass, propsType, stateType);
@@ -260,7 +262,10 @@ class ReactDebugMacro
260262

261263
js.Browser.console.warn(
262264
'Make sure your props are flattened, or implement shouldComponentUpdate.\n' +
263-
'See https://facebook.github.io/react/docs/optimizing-performance.html#shouldcomponentupdate-in-action'
265+
'See https://facebook.github.io/react/docs/optimizing-performance.html#shouldcomponentupdate-in-action' +
266+
'\n\nAlso note that legacy context API can trigger false positives if children ' +
267+
'rely on context. You can hide this warning for a specific component by adding ' +
268+
'`@${IGNORE_RERENDER_META}` meta to its class.'
264269
);
265270
}
266271
}

0 commit comments

Comments
 (0)