Fonto Why & How: Why is my configuration not applied?!

In this weekly series, Martin describes a question that was raised by a Fonto developer, how it was resolved and why Fonto behaved like that in the first place. A developer reached out. They want to open the outline view when the editor is opened, but the configuration is not picked up!

A support issue came in:

Hello Fonto,

Is it possible to make the outline view open by default? I am talking about the right-hand-side sidebar with the table of contents of the document. Is that possible?

A Fonto partner

Of course that is possible! Fonto Editor can be configured using the configurationManager. This manager has a set method to set final values of configuration, a setDefault method to set the default values that can be overwritten and a get to actually get a value. The configuration value for the outline view is called structure-view-configuration. There is a openStructureViewInitially property that can be set to open it by default.

Simple question, simple answer, right? Not worthy of a blogpost. But we got a response that we did not expect:

That does not seem to work. If I add configurationManager.set('structure-view-configuration', { openStructureViewInitially: true }); to my config/configuration.ts file, the editor starts with a hard error. If I use setDefault, I get no error, but the outline view is not open.

A Fonto partner

That is odd. After asking for the error message, we got this:

Error: Can not redefine configuration value "structure-view-configuration"
    at t.set (configurationManager.js:1:1363)
    at eval (configuration.ts:19:97)

This error tells that configurationManager.set is called with a key that is already set. That fits the other behaviour as well: if setting a default works, but is not applied, it means that somewhere else, there is a call to configurationManager.set('structure-view-configuration', {...}).

We replied with that question and the partner confirmed that was the issue. There was another call to the set method with the same value in another file. Merging the two configurations fixed the issue. The outline view opened by default and the partner could continue their work.

But why?

But why did the editor act up? How can this be prevented in the future?

As stated before, the configuration manager has two ways of setting configuration: setting default and setting final configuration. The bootstrapping in Fonto waits until all configuration values are applied and finalized before the rest of the source code is executed. Like I described in the blog post Fonto Why & How: Why is my configuration cyclic!?, configuration can get cyclic if the configuration.ts file depends on something that depends on config.

To apply defaults in the platform, we have files called setDefaultConfiguration.ts that are like configuration.ts. They are loaded before configuration.ts is loaded and they call configurationManager.setDefault to set up their defaults. If you are making your own package that may be reused in multiple editors, you can also use the setDefaultConfiguration.ts file to apply those defaults. You can read more here on our package structure.

The configuration.ts file is not intended to contain calls to configurationManager.setDefault: the configuration.ts file is going to be executed last in the whole chain. Setting more defaults there can only cause bugs like we’ve seen here: configuration not being applied because there’s a set in another file.

For this we have an internal story to address this and warn developers when they have a set for final configuration anywhere but in the configuration.ts and a warning if they set default configuration anywhere but in a setDefaultConfiguration.ts file.

I hope this explained how Fonto works and why it works like that. During the years we built quite the product, and we are aware some parts work in unexpected ways for those who have not been with it from the start. If you have any points of Fonto you would like some focus on, we are always ready and willing to share! Reach out on Twitter to Martin Middel or file a support issue!

Stay up-to-dateFonto Why & How posts direct in your inbox

Receive updates on new Fonto Why & How blog posts by email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top