Skip to content

Commit 01584bc

Browse files
committed
Fix loading of emojis JSON
Use `fetch` instead of Webpack (RSPack) chunks Updates #3764
1 parent 0c9facc commit 01584bc

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 11.0.2 (Unreleased)
44

55
- #3700: Fix exception that occurs when optional cp attribute is missing
6+
- #3730 QR Code is not valid
67
- Add approval banner in chats with requesting contacts or unsaved contacts
78
- Some fixes regarding manually resized chats in `overlayed` view mode.
89
- Replace webpack with [rspack](https://rspack.rs)

karma.conf.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ module.exports = function(config) {
1010
files: [
1111
{ pattern: 'dist/*.js.map', included: false },
1212
{ pattern: 'dist/*.css.map', included: false },
13-
{ pattern: "dist/emojis.js", served: true },
13+
{
14+
pattern: "dist/emoji.json",
15+
watched: false,
16+
included: false,
17+
served: true,
18+
type: 'json'
19+
},
1420
"src/shared/tests/tests.css",
1521
"dist/converse.js",
1622
"dist/converse.css",
@@ -162,6 +168,7 @@ module.exports = function(config) {
162168
],
163169

164170
proxies: {
171+
"/dist/emoji.json": "/base/dist/emoji.json",
165172
"/dist/images/custom_emojis/": "/base/dist/images/custom_emojis/",
166173
"/images/logo/": "/base/dist/images/logo/"
167174
},

rspack/rspack.build.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const plugins = [
8888
{ from: 'logo/conversejs-gold-gradient.svg', to: 'images/logo' },
8989
{ from: 'src/shared/styles/webfonts', to: 'webfonts' },
9090
{ from: 'manifest.json', to: 'manifest.json' },
91+
{ from: 'src/headless/plugins/emoji/emoji.json', to: 'emoji.json' },
9192
],
9293
}),
9394
];
@@ -103,10 +104,6 @@ module.exports = [
103104
},
104105
output: {
105106
filename: '[name].js',
106-
library: {
107-
type: 'umd',
108-
name: 'converse'
109-
}
110107
},
111108
}),
112109
// ESM Build
@@ -118,7 +115,8 @@ module.exports = [
118115
'converse.min': path.resolve(__dirname, '../src/entry.js'),
119116
},
120117
experiments: {
121-
outputModule: true
118+
outputModule: true,
119+
topLevelAwait: true,
122120
},
123121
output: {
124122
filename: '[name].esm.js',

src/headless/plugins/emoji/api.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@ const emojis = {
1111
* @method api.emojis.initialize
1212
* @returns {Promise}
1313
*/
14-
async initialize () {
14+
async initialize() {
1515
if (!converse.emojis.initialized) {
1616
converse.emojis.initialized = true;
1717

18-
const module = await import(/*webpackChunkName: "emojis" */ './emoji.json');
18+
let json;
19+
try {
20+
const path = api.settings.get('assets_path');
21+
const response = await fetch(`${path}/emoji.json`);
22+
if (!response.ok) throw new Error('Failed to fetch emoji.json');
23+
json = await response.json();
24+
} catch (e) {
25+
console.error('Failed to load emoji.json:', e);
26+
json = {};
27+
}
28+
1929
/**
2030
* *Hook* which allows plugins to modify emojis definition.
2131
*
@@ -37,24 +47,20 @@ const emojis = {
3747
* return json;
3848
* });
3949
*/
40-
const json = await api.hook('loadEmojis', {}, module.default);
50+
json = await api.hook('loadEmojis', {}, json);
4151
converse.emojis.json = json;
4252

43-
converse.emojis.by_sn = Object.keys(json).reduce(
44-
(result, cat) => Object.assign(result, json[cat]),
45-
{}
46-
);
53+
converse.emojis.by_sn = Object.keys(json).reduce((result, cat) => Object.assign(result, json[cat]), {});
4754
converse.emojis.list = Object.values(converse.emojis.by_sn);
4855
converse.emojis.list.sort((a, b) => (a.sn < b.sn ? -1 : a.sn > b.sn ? 1 : 0));
4956
converse.emojis.shortnames = converse.emojis.list.map((m) => m.sn);
50-
const getShortNames = () =>
51-
converse.emojis.shortnames.map((s) => s.replace(/[+]/g, '\\$&')).join('|');
57+
const getShortNames = () => converse.emojis.shortnames.map((s) => s.replace(/[+]/g, '\\$&')).join('|');
5258
converse.emojis.shortnames_regex = new RegExp(getShortNames(), 'gi');
5359
converse.emojis.initialized_promise.resolve();
5460
}
5561
return converse.emojis.initialized_promise;
5662
},
57-
}
63+
};
5864

5965
const emojis_api = { emojis };
6066

0 commit comments

Comments
 (0)