Skip to content

fix: give each picker its own options - #79

Merged
jonataswalker merged 3 commits into
masterfrom
fix/per-instance-options
Nov 16, 2026
Merged

jonataswalker merged 3 commits into
masterfrom
fix/per-instance-options

Conversation

@jonataswalker

@jonataswalker jonataswalker commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Implements spec #543: each TimePicker gets its own options object. Patch release (expected 5.0.1).

Bug

src/main.ts ran const options = Object.assign(DEFAULT_OPTIONS, opts). That writes the caller's options into the module-level DEFAULT_OPTIONS and returns that same object, so:

  • after new TimePicker(a, { theme: 'red', lang: 'pt' }), a later new TimePicker(b) is red with Portuguese labels
  • every picker shares one options object, so creating a picker with other options changes all earlier pickers' options

Every release with that line is affected, including 5.0.0.

Fix

const options = { ...DEFAULT_OPTIONS, ...opts }

Options holds only two strings (lang, theme), so a shallow copy is enough. DEFAULT_OPTIONS is no longer written anywhere.

Regression test first

tests/options-isolation.spec.ts, 2 tests × 3 projects (Chromium, Firefox, Mobile Chrome). Each creates two pickers on the test page:

Test Asserts
A picker created without options gets the defaults First picker { theme: 'red', lang: 'pt' }. Second picker gets { theme: 'dark', lang: 'en' }, Hour/Minute labels, and only classes the page's default picker also has (that picker is created at load, before any test code). Its classes differ from the first picker's. The page's default picker still reads dark/en.
A later picker leaves the earlier one unchanged First red/pt keeps its options and Hora/Minuto labels after a second blue/de picker (Stunde/Minute). Their classes differ, and the two don't share an options object.

The commits are in order:

  1. 8791cb4 adds the test alone. CI run 43943327063 failed on Node 22, 24 and 26 with exactly these 6 runs failing, for example: expected { lang: 'en', theme: 'dark' }, received { lang: 'pt', theme: 'red' }. The other 39 passed on each line.
  2. f3d4069 is the fix.

The test commit was made with HUSKY=0, because the pre-commit hook runs npm test, and a deliberately failing test can't pass it. Lint, typecheck and format were run by hand for that commit.

Gate

npm run verify exits 0 locally (Node 26.13.1, npm 12.2.2):

  • 45 Playwright tests (39 existing + 6 new)
  • attw, publint and the 6-file tarball check
  • packed consumers: declarations under bundler/nodenext, plus Chromium and Firefox selecting a time through the bundled ESM and the script-tag IIFE

version is untouched.

🤖 Generated with Claude Code

jonataswalker and others added 2 commits November 16, 2026 16:45
Two pickers on one page: a picker created without options must get the
defaults, a later picker with other options must leave the earlier one
unchanged, and the two must not share an options object. Fails on
5.0.0 because the constructor writes into the shared DEFAULT_OPTIONS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The constructor ran Object.assign(DEFAULT_OPTIONS, opts), which wrote
every caller's options into the module-level defaults and returned that
shared object. A picker created without options inherited an earlier
picker's theme and language, and creating a picker changed every
earlier picker's options. Spread the defaults and the caller's options
into a new object per instance instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonataswalker
jonataswalker force-pushed the fix/per-instance-options branch from ae1f91c to 8791cb4 Compare November 16, 2026 19:49
@jonataswalker
jonataswalker marked this pull request as ready for review November 16, 2026 19:53
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonataswalker
jonataswalker merged commit a242462 into master Nov 16, 2026
5 checks passed
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