Skip to content

Commit

Permalink
no-op React.cache if unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Oct 3, 2024
1 parent 4ff990b commit 56666b7
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import * as React from 'react'

const errorRef: { current: null | string } = { current: null }

// React.cache is currently only available in canary/experimental React channels.
const cache =
typeof React.cache === 'function'
? React.cache
: (fn: (key: unknown) => void) => fn

// We don't want to dedupe across requests.
// The developer might've just attempted to fix the warning so we should warn again if it still happens.
const flushCurrentErrorIfNew = React.cache(
const flushCurrentErrorIfNew = cache(
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- cache key
(key: unknown) => {
try {
Expand Down

0 comments on commit 56666b7

Please sign in to comment.