Skip to content

fix: detect inline props by content instead of timing in re-render warning - #63

Open
samtsai wants to merge 2 commits into
native-html:mainfrom
samtsai:fix/rerender-warning-content-check
Open

samtsai wants to merge 2 commits into
native-html:mainfrom
samtsai:fix/rerender-warning-content-check

Conversation

@samtsai

@samtsai samtsai commented Dec 2, 2026

Copy link
Copy Markdown

Problem

The dev-only re-render warning (useProfiler) fired whenever two updates of a watched prop happened within 60ms. In practice:

  • False positives on mount. Under React StrictMode, useMemo is replayed with identical inputs, so apps saw a burst of warnings at startup ("last update was 0.00ms ago") for TRenderEngineProvider, remoteErrorView or remoteLoadingView, renderers and renderersProps.
  • False positives on legitimate changes, e.g. a baseStyle that really changes quickly.
  • Missed the actual mistake. A parent re-rendering every 200ms with an inline tagsStyles rebuilds the engine on every render but never triggered the warning.
  • Vague and repetitive. It named groups of props (or none for TRenderEngineProvider), gave no fix, and logged on every fast update.

Change

Timing no longer matters. The hook now receives the values it watches and warns when a prop gets a new reference with identical content on two consecutive updates. That is the signature of an object, array or function created inline during render.

  • Content is compared deeply for plain objects and arrays, functions are compared by source, and class instances are compared by reference. Depth is capped, so cyclic values are safe.

  • Calls with unchanged references (StrictMode replays) are ignored.

  • Only the offending props are named, and each prop warns once per component instance.

  • The message explains the cause and the fix:

    You seem to pass a new "tagsStyles" value with identical content to the "TRenderEngineProvider" component on every render, causing costly tree re-renders. This usually happens when an object, array or function is created inline during render. Declare it outside of your component, or memoize it with useMemo or useCallback. See https://stackoverflow.com/q/68966120/2779871

All five call sites (TRenderEngineProvider config, renderers, renderersProps, remoteErrorView/remoteLoadingView, onDocumentMetadataLoaded/onTTreeChange) now pass their values. The FAQ troubleshooting heading is updated to match the new wording.

Tests

New src/hooks/__tests__/useProfiler.test.tsx (13 tests) covers the equality helper, the hook, and RenderHTML under StrictMode: no warnings on mount with inline props, one warning for an inline tagsStyles across re-renders, and none for stable or genuinely changing props. Against the old implementation, the StrictMode mount test reproduces the startup warnings.

  • jest src/: 278 passed
  • eslint src/: clean
  • tsc --noEmit: no errors in the changed files. Locally, the package-wide type check fails on unrelated Cannot find module '@native-html/transient-render-engine' errors because that workspace package isn't built.

🤖 Generated with Claude Code

samtsai and others added 2 commits December 2, 2026 11:25
…rning

The re-render warning used to fire whenever two updates happened within
60ms, which caused false positives on mount under React StrictMode (memo
replays) and for props that genuinely change quickly, while missing
inline props on slower re-renders.

It now warns when a prop receives a new value with identical content
(deep comparison, functions compared by source) on consecutive updates,
names only the offending props, warns once per prop, and suggests how
to fix it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The comparison and message helpers lived at module level and were
exported, so minifiers could not drop them when __DEV__ is false. They
now live inside the dev-only branch, and the production build of the
hook is just a no-op.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant