Skip to content

feat(fluent-dom): Add an option to connectRoot to opt out of the mutation observer - #671

Open
julienw wants to merge 1 commit into
projectfluent:mainfrom
julienw:support-opting-out-mutation-observer
Open

julienw wants to merge 1 commit into
projectfluent:mainfrom
julienw:support-opting-out-mutation-observer

Conversation

@julienw

@julienw julienw commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

This is a workaround for issue #648.

In apps that are primarily implemented with WebComponents, the number of roots can grow a lot. This proved to be a performance issue. So instead of using a MutationObserver to run translations, the WebComponent framework can call the translate functions directly as part of its lifecycle.

@julienw

julienw commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

What do you think @eemeli ?

@julienw julienw changed the title fix: Add an option to connectRoot to opt out of the mutation observer feat(fluent-dom): Add an option to connectRoot to opt out of the mutation observer Sep 15, 2026
…tion observer

This is a workaround for issue projectfluent#648.

In apps that are primarily implemented with WebComponents, the number of
roots can grow a lot. This proved to be a performance issue. So instead
of using a MutationObserver to run translations, the WebComponent
framework can call the translate functions directly as part of its
lifecycle.
@julienw
julienw force-pushed the support-opting-out-mutation-observer branch from 73318b4 to b834edc Compare September 15, 2026 12:36
connectRoot(newRoot, opts = {}) {
const useObserver = "useObserver" in opts ? opts.useObserver : true; // Defaults to true

for (const root of this.roots) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that this loop is also quadratic when a lot of roots are added, and it's very unlikely for Lit-based apps, plus the drawbacks of not doing this check is very low if I understand this correctly (again, in a lit-based app where each root has a small DOM).

Maybe a better solution would be a separate localization class... I'll look into that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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