Skip to content

Update memoize-one 6.0.0 → 7.0.0 (major) - #6494

Merged
fatadel merged 2 commits into
mainfrom
depfu/update/yarn/memoize-one-7.0.0
Nov 30, 2026
Merged

fatadel merged 2 commits into
mainfrom
depfu/update/yarn/memoize-one-7.0.0

Conversation

@depfu

@depfu depfu Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Main | Deploy preview

Here is everything you need to know about this upgrade. Please take a good look at what changed and the test results before merging this pull request.

What changed?

✳️ memoize-one (6.0.0 → 7.0.0) · Repo

Release Notes

7.0.0

Uplifting memoize-one so it continues to be a good choice for new projects

At a glance

  • 📦 Moving to ES module only
  • 🟰 Arguments comparison now uses Object.is
  • 🪶 20% smaller: 319 B → 258 B (minified and gzipped). Still no dependencies 🎉
  • 🏋️‍♀️ Better types for custom equality functions

For most people, upgrading to 7.0.0 should be trivial.

The two changes that might impact you:

  1. memoize-one is now an ES module only package
  2. Arguments are compared with Object.is, so +0 and -0 are now different arguments

If you need to support older environments you can use memoize-one@6

Breaking: ES module only 📦

memoize-one now ships a single ES module (dist/memoize-one.js) along with its types. The CommonJS and UMD builds are gone.

Supported environments

  • Browsers: Any browser that supports es2022
  • Bundlers: All bundlers that support ES modules and es2022
  • Node.js: import works in all supported versions. require() works in Node.js 20.19+ and 22.12+ (thanks to require(esm))

If you use require()

require() now gives you the module, not the function:

// v6
const memoizeOne = require('memoize-one');

// v7 (Node.js 20.19+ and 22.12+)
const { memoizeOne } = require('memoize-one');

If you use TypeScript and compile to CommonJS

Use "module": "nodenext" (TypeScript 5.8+) or "module": "node20" (TypeScript 5.9+). With node16 or node18, TypeScript reports error TS1479 for require() of an ES module. You can use a dynamic import() instead.

If you used the UMD build from a CDN

Load the module instead:

<script type="module">
  import { memoizeOne } from 'https://cdn.jsdelivr.net/npm/memoize-one@7/+esm';
</script>

If you imported a file from dist

The exports map blocks deep imports such as memoize-one/dist/memoize-one.esm.js. Import from memoize-one instead.

If you use Jest

Jest uses its own module loader, not Node's require(esm). So tests that run as CommonJS fail with "Must use import to load ES Module". You have two options:

  • Node.js 24.9+: run Jest with NODE_OPTIONS=--experimental-vm-modules (Node.js prints an ExperimentalWarning)
  • Any Node.js version: let Babel transform memoize-one into CommonJS. You need both files below. It must be a babel.config.js file, as a .babelrc file does not apply to node_modules
// jest.config.js
module.exports = {
  transformIgnorePatterns: ['/node_modules/(?!memoize-one/)'],
};
// babel.config.js
module.exports = {
  presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
};

→ More details in the upgrade guide

This change also sorts out the TypeScript module resolution problems raised in #267 and #270.

Breaking: arguments are compared with Object.is 🟰

Previously, our default equality check used ===, with a special case for NaN (added in 5.2.0). We now use Object.is. This is the same comparison that React uses for hook dependencies (such as in useMemo).

NaN is still equal to NaN. The only change is that +0 and -0 are now different arguments:

const memoizedAdd = memoizeOne(add);

memoizedAdd(0);
memoizedAdd(-0);
// v6: cache hit (0 === -0)
// v7: add is called again (Object.is(0, -0) is false)

The this context is also compared with Object.is.

I don't expect many people to be impacted by this. But as it is a behaviour change, it is part of the major

If you need the old behaviour, you can pass in a custom equality function:

import { memoizeOne } from 'memoize-one';

const memoizedAdd = memoizeOne(
add,
(newArgs, lastArgs) =>
newArgs.length === lastArgs.length &&
newArgs.every(
(arg, i) => arg === lastArgs[i] || (Number.isNaN(arg) && Number.isNaN(lastArgs[i])),
),
);

Breaking: goodbye ie11 👋

memoize-one is now written in ES2022 syntax, so Internet Explorer 11 is no longer supported. See the supported environments above.

Breaking: no more Flow types

memoize-one started its life written in Flow, and kept shipping Flow types after it moved to TypeScript in 5.1.0. The Flow type definitions are no longer included. Thanks for all the good times Flow ❤️

Possibly breaking: stricter types with EqualityFn<any>

If you typed your equality function as EqualityFn<any>, the memoized function used to be MemoizedFn<any>, so its arguments and return value were any 😬. It now keeps the type of the function you memoize, so TypeScript might report errors that were hidden before.

const isEqual: EqualityFn<any> = (newArgs, lastArgs) => newArgs[0] === lastArgs[0];

const memoizedAdd = memoizeOne(add, isEqual);
// v6: MemoizedFn<any>
// v7: MemoizedFn<typeof add>

New: named exports 🏷️

import { memoizeOne } from 'memoize-one';

The default export still works, so you do not need to change your imports:

import memoizeOne from 'memoize-one';

New: areInputsEqual export

Our default equality check is now exported, so you can build on top of it. For example, to ignore the last argument:

import { memoizeOne, areInputsEqual } from 'memoize-one';

const memoized = memoizeOne(format, (newArgs, lastArgs) =>
areInputsEqual(newArgs.slice(0, -1), lastArgs.slice(0, -1)),
);

Improved: types 🏋️‍♀️

  • EqualityFn now has a default type argument, so you can write one equality function and reuse it:
import { memoizeOne, areInputsEqual, type EqualityFn } from 'memoize-one';

const ignoreLastArg: EqualityFn = (newArgs, lastArgs) =>
areInputsEqual(newArgs.slice(0, -1), lastArgs.slice(0, -1));

const memoizedFormat = memoizeOne(format, ignoreLastArg);
const memoizedParse = memoizeOne(parse, ignoreLastArg);

  • The memoized function type now comes from your result function, not your equality function
  • memoizeOne, areInputsEqual, EqualityFn and MemoizedFn now have JSDoc, so you get docs right in your editor
  • Types are checked with publint and arethetypeswrong

Improved: even smaller 🪶

memoize-one was already tiny, and it is now about 20% smaller: 319 B → 258 B (minified and gzipped). Still no dependencies 🎉

Improved: documentation

  • New upgrading from v6 guide
  • New supported environments section
  • How to set .length on a memoized function (#38)
  • Documented where MemoizedFn simplifies a signature (overloads, generics and type predicates)
  • Refreshed performance benchmarks on Node.js 24, against the latest versions of other libraries
  • Examples now use isEqual from es-toolkit for deep equality (instead of lodash.isequal)

Internal code health

  • Now on TypeScript@7, and built with plain tsc (goodbye Rollup and friends)
  • Moved from Jest to Vitest
  • Moved from ESLint to oxlint
  • Moved from yarn to npm
  • One CI workflow, testing on Node.js 22, 24 and 26
  • Every build is smoke tested with import and require() on each Node.js version
  • Upgraded all devDependencies

Thanks ❤️

Thanks so much to the following people who helped make this release possible:

Cheers,
Alex

Does any of this look wrong? Please let us know.

Commits

See the full diff on Github. The new version differs by 45 commits:


Depfu Status

Depfu will automatically keep this PR conflict-free, as long as you don't add any commits to this branch yourself. You can also trigger a rebase manually by commenting with @depfu rebase.

All Depfu comment commands
@​depfu rebase
Rebases against your default branch and redoes this update
@​depfu recreate
Recreates this PR, overwriting any edits that you've made to it
@​depfu merge
Merges this PR once your tests are passing and conflicts are resolved
@​depfu cancel merge
Cancels automatic merging of this PR
@​depfu close
Closes this PR and deletes the branch
@​depfu reopen
Restores the branch and reopens this PR (if it's closed)
@​depfu pause
Ignores all future updates for this dependency and closes this PR
@​depfu pause [minor|major]
Ignores all future minor/major updates for this dependency and closes this PR
@​depfu resume
Future versions of this dependency will create PRs again (leaves this PR as is)

@depfu
depfu Bot requested review from canova and fatadel as code owners November 30, 2026 00:11
@depfu depfu Bot added the dependencies Pull requests that update a dependency file label Nov 30, 2026
memoize-one 7 ships as an ES module only, so Jest can't require() it
unless Babel transforms it.
@fatadel
fatadel added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit dbb1d36 Nov 30, 2026
21 checks passed
@depfu
depfu Bot deleted the depfu/update/yarn/memoize-one-7.0.0 branch November 30, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant