Skip to content

fix: keep prototype-named classes without string mappings - #593

Open
feritcemkahraman wants to merge 1 commit into
JedWatson:mainfrom
feritcemkahraman:fix/bind-prototype-class-names
Open

feritcemkahraman wants to merge 1 commit into
JedWatson:mainfrom
feritcemkahraman:fix/bind-prototype-class-names

Conversation

@feritcemkahraman

Copy link
Copy Markdown

With const cx = classNames.bind({ a: 'a_hash' }), cx('constructor') and cx({ constructor: true }) return the native Object function instead of a class string. Other names inherited from Object.prototype can also corrupt combined class lists.

Use a bound mapping only when its value is a string. This keeps unmapped names intact and preserves explicit prototype-named mappings, inherited string mappings, and the existing empty-string fallback. Each mapping is read once.

Both string and object regressions fail before the fix. All 66 Node tests and the TypeScript declaration checks pass with the fix.

Local performance smoke check

Compared the unchanged main bind implementation with this change on Node 24.21.0, using bound styles and the benchmark's string, object, mixed, and nested-array argument shapes. Median of seven alternating runs, 200,000 calls per sample, after warmup, on one logical CPU:

Arguments Before (ms) After (ms)
Strings 17.69 17.73
Object 14.68 15.19
Mixed 20.62 20.99
Arrays 64.36 61.21

The browser/JSPerf benchmark and the older Node matrix were not run locally.

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