Assets only available to SCSS not JS

סיכום מבוסס בינה מלאכותית

In a discussion about theme assets in Discourse, hakonbja reports that assets added to the assets folder and referenced in about.json are available in SCSS but not appearing in settings.theme_uploads for JavaScript use — even after removal, assets persist in the settings object. merefield echoes confusion, noting settings.theme_uploads returns undefined in JavaScript computed properties, questioning when it’s safe to reference it. david clarifies that settings.theme_uploads was added recently and should be reliable, used internally in official themes. merefield resolves their issue: they had omitted the assets/ prefix in the asset path in about.json, causing the asset to be ignored and returning undefined in JS. Correcting the path (e.g., "background": "assets/background.png") fixed the problem. They confirm usage in an Ember component via settings.theme_uploads.background. merefield apologizes for the oversight and asks hakonbja if they resolved their issue.

Hello,

For the last week or so I’ve been styling a Discourse setup for a brand which includes fixed fonts, logos and icons.

To begin with I noticed that any assets I imported (place in assets folder and import under the assets object of about.json) became immediately available to use as a SCSS variable but took a minute or two to show up in settings.theme_uploads.

Now however, they don’t show up at all in settings.theme_uploads which means I can’t use them in my JavaScript. If I remove an asset it also stays in the settings object. The SCSS usage stays unaffected.

Help would be greatly appreciated.

Yeah, I’m a bit confused by this too.

At what point is it safe to use a reference like return settings.theme_uploads.blah in javascript if ever?

I’m getting “undefined” for settings.theme_uploads in my computed property (initially at least).

What’s the right pattern here?

The settings.theme_uploads data was added to javascript relatively recently (after the OP was written, I think). It should be reliable - we use it in our own themes/components. Can you explain in more details what issues you’re seeing?

Ah, I was missing the assets folder in my path to the asset, so the broken link had “optimised out” the asset no doubt:

{
  "name": "Cool Theme Component",
  "about_url": "",
  "component": true,
  "assets": {
    "background": "background.png"
  }
}

should have been:

{
  "name": "Cool Theme Component",
  "about_url": "",
  "component": true,
  "assets": {
    "background": "assets/background.png"
  }
}

Doh!

FYI I’m reference this in Javascript in an Ember Component, e.g.:

  @computed
  backgroundImage() {
    return settings.theme_uploads.background;
  }

That would raise an undefined error when the path is incorrect!

Thanks for listening! @david, sorry to waste your time.

@hakonbja did you solve your issue?