Skip to content

fix(popover): support non-writable polyfilled methods - #5188

Open
olemartinorg wants to merge 1 commit into
digdir:mainfrom
olemartinorg:fix/writable-popover-wrappers
Open

fix(popover): support non-writable polyfilled methods#5188
olemartinorg wants to merge 1 commit into
digdir:mainfrom
olemartinorg:fix/writable-popover-wrappers

Conversation

@olemartinorg

@olemartinorg olemartinorg commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

The shadow DOM support added wrappers around HTMLElement.prototype.togglePopover, showPopover, and hidePopover using direct assignment. That works for native browser implementations, but @oddbird/popover-polyfill defines these methods as configurable and non-writable. Assigning to them throws a TypeError while the Designsystemet module is loading.

We discovered this while upgrading Altinn from Designsystemet 1.18.0 through 1.19.0 as part of Altinn/altinn-studio#19766. In Altinn's JSDOM/Vitest suite, importing any Designsystemet React component failed with:

TypeError: Cannot assign to read only property 'togglePopover' of object '#<HTMLElement>'

Because the exception happened during module initialization, 118 test suites failed before collecting their tests, blocking progress on the upgrade.

This change installs the wrappers with Object.defineProperty, preserving the existing descriptors while explicitly making the replacement methods writable. Hot-reload cleanup now restores the complete original descriptors instead of assigning the function values back. The web test setup mirrors the non-writable descriptor shape from the polyfill so this compatibility path remains covered in browsers with native popover support.

Downstream verification in Altinn removed the import-time exception, our tests pass again.

Checks performed:

  • Biome check passed for the changed TypeScript files.
  • TypeScript passed for packages/web.
  • Designsystemet types, web, CSS, and React package builds passed before the final no-behavior inlining cleanup.

Checks

The OddBird popover polyfill installs configurable methods without marking
them writable. Assigning shadow-DOM wrappers directly therefore throws during
module initialization in environments such as JSDOM, preventing every
consumer test that imports Designsystemet from collecting tests.

Redefine the methods through their property descriptors and restore those
original descriptors during hot reload. Exercise the polyfilled descriptor
shape in the web test setup so native-browser test runs cover this failure.
@changeset-bot

changeset-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 76ea0e9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@digdir/designsystemet-web Patch
@digdir/designsystemet Patch
@digdir/designsystemet-css Patch
@digdir/designsystemet-types Patch
@digdir/designsystemet-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@olemartinorg
olemartinorg marked this pull request as ready for review August 13, 2026 14:52
@eirikbacker

eirikbacker commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Hi @olemartinorg! Thanks for reporting and fantastic you make PRs directly to us! 🌟 Really appreciate it 🙏 We have noticed this issue too, and already have a PR fixing it, patching the oddbird polyfill locally in our code, while we wait for oddbird/popover-polyfill#291 to be released ☺️ We'll look into your work here and merge our approaches ☺️

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.

2 participants