diff --git a/handleMessage.js b/handleMessage.js index e273361..07f72db 100644 --- a/handleMessage.js +++ b/handleMessage.js @@ -1,22 +1,33 @@ 'use strict'; -const wordnet = require('wordnet'); - +// `wordnet` is a server-only package (it reads the WordNet database off disk). +// It MUST NOT be required at module top level: Etherpad's client bundler pulls +// plugin hook modules into the browser bundle, and evaluating wordnet's module +// body in the browser silently hangs the editor bootstrap — the ace_outer +// iframe is never created and no error is thrown, so every pad (and the whole +// frontend test suite) times out. Requiring it lazily inside the hook keeps the +// module body from ever running client-side while still working on the server. +let wordnet = null; let initPromise = null; const ensureInit = () => { + if (!wordnet) wordnet = require('wordnet'); if (!initPromise) initPromise = wordnet.init(); return initPromise; }; const sendDefinition = (context, definitions) => { - context.client.json.send({ + // `context.client.json.send(...)` was the socket.io v2 API and no longer + // exists, so the reply never reached the client (the gritter never showed). + // Emit over the modern socket, and trust the server-resolved author/pad from + // sessionInfo rather than client-supplied ids. + context.socket.emit('message', { type: 'COLLABROOM', data: { type: 'CUSTOM', payload: { action: 'recieveDefineMessage', - authorId: context.message.data.message.myAuthorId, - padId: context.message.data.message.padId, + authorId: context.sessionInfo.authorId, + padId: context.sessionInfo.padId, message: definitions, }, }, @@ -26,7 +37,10 @@ const sendDefinition = (context, definitions) => { exports.handleMessage = async (hookName, context) => { if (!(context && context.message && context.message.data && context.message.data.type && context.message.data.action === 'sendDefineMessage')) { - return [null]; + // Not our message — return nothing so the message keeps flowing. Returning + // `[null]` here would tell core to DROP every non-define message (typing, + // cursor moves, …), silently breaking the pad. + return; } try { await ensureInit();