# Accessing other instance in WidgetType.updateDOM

**URL:** <https://discuss.codemirror.net/t/accessing-other-instance-in-widgettype-updatedom/9693>\
**Category:** v6\
**Created:** [March 11, 2026, 8:11am UTC](https://discuss.codemirror.net/t/accessing-other-instance-in-widgettype-updatedom/9693 "2026-03-11T08:11:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![push-f](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/p/ce73a5/32.png) [@push-f](https://discuss.codemirror.net/u/push-f)\
**Post date:** [March 11, 2026, 8:11am UTC](https://discuss.codemirror.net/t/accessing-other-instance-in-widgettype-updatedom/9693/1 "2026-03-11T08:11:26Z")

</div>

When using CodeMirror within a frontend framework like Svelte, you probably also want to use the framework to implement the DOM for [WidgetType](https://codemirror.net/docs/ref/#view.WidgetType)s, however [WidgetType.updateDOM](https://codemirror.net/docs/ref/#view.WidgetType.updateDOM) only gets a reference to the old DOM element, not to the old instance of the same class (that with e.g. Svelte would hold the component reference). As a workaround I can store the references in a map and attach ids to the wrapper DOM elements to enable the lookup of the component references in `updateDOM` but it would be convenient if CodeMirror just provided the old instance as a parameter.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [March 11, 2026, 9:03am UTC](https://discuss.codemirror.net/t/accessing-other-instance-in-widgettype-updatedom/9693/2 "2026-03-11T09:03:26Z")

</div>

That sounds like a good idea. This patch implements it:

> <https://github.com/codemirror/view/commit/9373f525a2aef0e7b2b7159470b8940f5b3d474a>
>
> FEATURE: \`WidgetType.updateDOM\` is now called with the previous widget value
> as …third argument.
> 
> See https://discuss.codemirror.net/t/accessing-other-instance-in-widgettype-updatedom/9693

---

<div class="post-metadata">

**Author:** ![push-f](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/p/ce73a5/32.png) [@push-f](https://discuss.codemirror.net/u/push-f)\
**Post date:** [March 11, 2026, 6:17pm UTC](https://discuss.codemirror.net/t/accessing-other-instance-in-widgettype-updatedom/9693/3 "2026-03-11T18:17:01Z")

</div>

Awesome thanks! Works like a charm. Just sent a PR to slightly improve the type of the new parameter: [Change WidgetType.updateDOM from type to this by not-my-profile · Pull Request #81 · codemirror/view · GitHub](https://github.com/codemirror/view/pull/81)
