You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable React Compiler in the Next.js app so eligible components and hooks can reuse previous work instead of repeating it on every render.
This should be a very passive change, not requiring additional effort to write components. The idea is that the compiler will help 'auto-memoise' components, so having to use the likes of useMemo and useCallback shouldn't be needed as the compiler will handle that for you.
You can opt-out of the React Compiler using the use no memo directive at the top of components and hooks: React Compiler escape hatch but this should be used sparingly, if at all.
Similarly, you can add 'overrides' to the eslintrc file to ignore or change the level of error for compiler rules. This too should be used very sparingly.
If code breaks one of the compiler's rules, ESLint reports it as an error from the react-hooks plugin. For example, calling setState synchronously inside an effect produces:
src/app/hooks/useActionTooltip/index.ts
24:23 error Error: Calling setState synchronously within an effect can trigger cascading renders
Effects are intended to synchronize state between React and external systems such as manually updating the DOM, state management libraries, or other platform APIs. In general, the body of an effect should do one or both of the following:
* Update external systems with the latest state from React.
* Subscribe for updates from some external system, calling setState in a callback function when external state changes.
Calling setState synchronously within an effect body causes cascading renders that can hurt performance, and is not recommended. (https://react.dev/learn/you-might-not-need-an-effect).
22 |
23 | useEffect(() => {
> 24 | if (actionResult) setIsTooltipVisible(true);
| ^^^^^^^^^^^^^^^^^^^ Avoid calling setState() directly within an effect
25 | }, [actionResult]);
26 | react-hooks/set-state-in-effect
The fix is usually to derive the value during render, or to move the work into an event handler, rather than to disable the rule.
Code changes
Enable the supported top-level reactCompiler: true Next.js option.
Add babel-plugin-react-compiler dependency. Required to allow the compiler to work.
Update various components to 'satisfy' the React Compiler and adds tests around the new behaviour to ensure they behave as expected under the new compiler
Enable automatic client-side memoization across all services using the supported Next.js integration. Preserve the existing Emotion, SSR and AMP/Lite pipelines.
Keep configuration, the pinned dependency and tracked cache, regression tests, and documentation together so the rollout can be reverted atomically.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Depend directly on the extracted experiment props so React Compiler can preserve context memoization. Cover stable references and analytics updates, and remove the manual-memoization lint override.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep polling callbacks and parameters fresh without mutating refs during render, and ignore in-flight responses after effect cleanup. Cover updates, cancellation and timing, and remove the resolved polling refs override.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Derive redundant UI state directly, subscribe to browser state with hydration-safe snapshots, and track scroll milestones without extra renders. Cover browser changes, image cancellation, PWA prompt cleanup and time-machine lifecycle.
Remove ten resolved set-state-in-effect overrides; retain the blocked media and webcore entries pending their styling migrations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Allow error-summary tests to render more than twice without falling back to an empty context, and restore spies between tests. Cover the hydration-safe Android hook without relying on internal render counts.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pass experiment variants into pure ATI enrichment functions and own experiment Hooks in stable React component boundaries. Preserve eligible page types and reset experiment state safely when eligibility changes.
Cover page transitions and real Hook state. Verified production hydration on seven routes and client-side navigation between home, article and non-experiment pages.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove shared mutable render variables from related-content, top-stories and latest-media lists without changing markup or styles.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reuse hydration detection instead of synchronously copying localized dates and times into state from effects. Preserve existing component types, markup and styles; cover hydration and fixture/service updates.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep render-time refs immutable while retaining fresh fullscreen and swipe callbacks without reloading players. Reuse hydration detection for the fullscreen portal, preserving all existing component formats and styling.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Read dropdown DOM measurements in the layout lifecycle instead of during render, preserving existing JSX and Emotion styling. Remove the final compiler warning override after validating menu height and open/close behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Exclude Fullscreen API elements from fullscreen PWA detection while retaining fullscreen installed-app support. Cover video fullscreen enter/exit and reuse of the saved install prompt without another beforeinstallprompt event.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
If deferPrompt changes while prompt() or userChoice is pending, effect cleanup deactivates the captured session but leaves installPrompt in state. Once the choice settles, the inactive-session guards prevent clearing that consumed event. Re-enabling deferral then reports it as installable and permits another prompt() call on the used event. Keep callback cancellation separate from event cleanup: finish consuming the choice and clear only the matching event, so a newer event is not discarded. Add a regression test that toggles deferPrompt during the pending operation.
Keep a stable per-hook snapshot reader that retains the established app mode while native video fullscreen temporarily replaces display-mode. Continue observing real display-mode changes outside fullscreen, with regression coverage for all supported app modes and rerenders.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Compiler-wide activation and broad lifecycle refactors require cross-service build and runtime validation before human approval.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Return immutable location snapshots to trigger navigation-dependent effects
src/app/hooks/useLocation/index.tsx:18
The href snapshot changes on navigation, but this hook still returns the same mutable window.location object. Consumers that depend on its identity, such as the effect in components/Ad/Canonical/index.tsx:46–64, therefore do not rerun; compiler memoization can also reuse calculations based on that unchanged identity. Return a read-only location snapshot cached per href, and test a consumer with [location] dependencies across navigation. Update the existing tests that expect previously returned values to mutate after pushState.
Preserve the published commit history while integrating upstream changes. Retain the validated conflict resolutions and Jest mock compatibility fixes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
This override is due to the sticky nav we're currently testing. It has a lot of state management which works for test purposes, but will need refactored to satisfy the compiler. Don't want to do that here in this piece of work as its code thats still under development.
Resetting moment.now during render mutates a module-level value, which the
React Compiler's react-hooks/immutability rule rejects. Restore it in an
effect cleanup instead so the fixed story time does not leak into other
stories.
amoore108
changed the title
Enable React Compiler in Next.js
perf: Enable React Compiler in Next.js
Nov 28, 2026
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable React Compiler in the Next.js app so eligible components and hooks can reuse previous work instead of repeating it on every render.
This should be a very passive change, not requiring additional effort to write components. The idea is that the compiler will help 'auto-memoise' components, so having to use the likes of
useMemoanduseCallbackshouldn't be needed as the compiler will handle that for you.You can read more about the React Compiler here.
You can opt-out of the React Compiler using the
use no memodirective at the top of components and hooks: React Compiler escape hatch but this should be used sparingly, if at all.Similarly, you can add 'overrides' to the
eslintrcfile to ignore or change the level of error for compiler rules. This too should be used very sparingly.If code breaks one of the compiler's rules, ESLint reports it as an error from the
react-hooksplugin. For example, callingsetStatesynchronously inside an effect produces:The fix is usually to derive the value during render, or to move the work into an event handler, rather than to disable the rule.
Code changes
reactCompiler: trueNext.js option.babel-plugin-react-compilerdependency. Required to allow the compiler to work.Useful Links