FriendsOfFlarum / byobu

Well integrated, advanced private discussions for your Flarum forum.
https://discuss.flarum.org/d/4762-flagrow-by-bu-well-integrated-advanced-private-discussions
MIT License
54 stars 33 forks source link

Submitting private discussions ends up in JS error #104

Closed patschi closed 4 years ago

patschi commented 4 years ago

When submitting a private discussion it ends up in a JS error: image

The error:

Model.js:303 Uncaught TypeError: Cannot read property 'data' of undefined
    at t.getIdentifier (Model.js:303)
    at Array.map (<anonymous>)
    at e.save (Model.js:142)
    at e.s.onsubmit (PrivateDiscussionComposer.js:30)
    at e.<anonymous> (removeTags.js:16)
    at e.t.<computed> (extend.js:61)
    at e.<anonymous> (removeTags.js:16)
    at e.t.<computed> (extend.js:61)
    at e.<anonymous> (removeTags.js:16)
    at e.t.<computed> (extend.js:61)
    at e.n.onsubmit (TextEditor.js:182)
    at HTMLButtonElement.H.t.<computed> (mithril.js:1286)
t.getIdentifier @ Model.js:303
e.save @ Model.js:142
s.onsubmit @ PrivateDiscussionComposer.js:30
(anonymous) @ removeTags.js:16
t.<computed> @ extend.js:61
(anonymous) @ removeTags.js:16
t.<computed> @ extend.js:61
(anonymous) @ removeTags.js:16
t.<computed> @ extend.js:61
n.onsubmit @ TextEditor.js:182
H.t.<computed> @ mithril.js:1286

Flarum info:

Flarum core 0.1.0-beta.12
PHP version: 7.4.3
Loaded extensions: Core, date, libxml, openssl, pcre, zlib, filter, hash, pcntl, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, bcmath, bz2, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, igbinary, imagick, imap, intl, json, exif, memcache, msgpack, mysqli, PDO_Firebird, pdo_mysql, pdo_sqlite, Phar, posix, readline, shmop, SimpleXML, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, zip, memcached, Zend OPcache
+---------------------------------+----------------+--------+
| Flarum Extensions               |                |        |
+---------------------------------+----------------+--------+
| ID                              | Version        | Commit |
+---------------------------------+----------------+--------+
| flarum-approval                 | v0.1.0-beta.12 |        |
| flarum-bbcode                   | v0.1.0-beta.12 |        |
| flarum-emoji                    | v0.1.0-beta.12 |        |
| flarum-lang-english             | v0.1.0-beta.12 |        |
| flarum-flags                    | v0.1.0-beta.12 |        |
| flarum-likes                    | v0.1.0-beta.12 |        |
| flarum-lock                     | v0.1.0-beta.12 |        |
| flarum-markdown                 | v0.1.0-beta.12 |        |
| flarum-mentions                 | v0.1.0-beta.12 |        |
| flarum-statistics               | v0.1.0-beta.12 |        |
| flarum-sticky                   | v0.1.0-beta.12 |        |
| flarum-subscriptions            | v0.1.0-beta.12 |        |
| flarum-suspend                  | v0.1.0-beta.12 |        |
| flarum-tags                     | v0.1.0-beta.12 |        |
| noriods-auto-more               | 0.3.0          |        |
| flagrow-sitemap                 | 0.2.0          |        |
| fof-drafts                      | 0.1.4          |        |
| fof-follow-tags                 | 0.3.4          |        |
| fof-forum-statistics-widget     | 0.1.1          |        |
| fof-links                       | 0.2.1          |        |
| fof-moderator-notes             | 0.1.1          |        |
| fof-nightmode                   | 0.4.0          |        |
| fof-pwned-passwords             | 0.3.0          |        |
| fof-share-social                | 0.1.2          |        |
| fof-socialprofile               | 0.1.1          |        |
| fof-spamblock                   | 0.2.1          |        |
| fof-upload                      | 0.8.3          |        |
| v17development-seo              | 1.1            |        |
| the-turk-quiet-edits            | 0.1.1          |        |
| the-turk-password-strength      | 0.1.2          |        |
| clarkwinkelmann-lock-likes      | 1.0.0          |        |
| fof-recaptcha                   | 0.1.2          |        |
| fof-terms                       | 0.4.1          |        |
| zerosonesfun-hashtags           | 1.4.2          |        |
| fof-pages                       | 0.3.1          |        |
| fof-formatting                  | 0.1.4          |        |
| fof-disposable-emails           | 0.1.0          |        |
| wiwatsrt-best-answer            | v0.2.4         |        |
| michaelbelgium-discussion-views | v3.1.0         |        |
| clarkwinkelmann-circle-groups   | 0.2.1          |        |
| fof-username-request            | 0.2.0          |        |
| reflar-twofactor                | 0.1.3          |        |
| fof-byobu                       | 0.4.4          |        |
| zerosonesfun-announce           | 1.3            |        |
| fof-reactions                   | 0.2.1          |        |
| flagrow-analytics               | 0.8.0          |        |
| fof-pretty-mail                 | 0.1.6          |        |
| fof-user-directory              | 0.3.4          |        |
| reflar-level-ranks              | 1.2.1          |        |
| fof-filter                      | 0.1.0-beta.2   |        |
| the-turk-diff                   | 0.1.0-beta.7   |        |
| zerosonesfun-spoiler            | 1.2            |        |
| zerosonesfun-tooltip            | 1.1            |        |
| fof-prevent-necrobumping        | 0.2.0          |        |
| fof-stopforumspam               | 0.2.1          |        |
| fof-default-user-preferences    | 0.2.0          |        |
+---------------------------------+----------------+--------+
Debug mode: off

I know the error is not really helpful, but please just let me know if you need any further details. Thanks for any help in advance!

clarkwinkelmann commented 4 years ago

@patschi can you try disabling some of the third-party extensions to see if the issue goes away ?

Another thing that could be helpful, are you able to check the network tab any copy the response data of the last request (I believe it's a POST request to /api/discussions)

patschi commented 4 years ago

The error appears across different users, and no request sent to the server - it fails in the browser before actually sending any data to the server (so no POST request). I believe it's also somehow caused by a other extension, but I have no idea which one.

Enabling/Disabling all extensions is quite time-consuming by this amount of extensions (luckily the site isn't fully live yet). But I guess you're right and that this is the only way narrowing it down further. As I'm pretty new to Flarum and its extensions and I don't know it in-depth, do you have any tips where to start looking?

clarkwinkelmann commented 4 years ago

To find out which extension conflict, I'd suggest:


Alternatively, the backtrace of the error in the console could allow you to find out which extension it was. You can look at each line listed there, and if it's part of the source of an extension it's possible to find which one it is. But it's not user friendly because it requires looking at code that has been compiled.

patschi commented 4 years ago

Actually when reading the thrown JS error:

Uncaught TypeError: Cannot read property 'data' of undefined
    at t.getIdentifier (Model.js:303)
    at Array.map (<anonymous>)
    at e.save (Model.js:142)
    at e.s.onsubmit (PrivateDiscussionComposer.js:30)
    at e.<anonymous> (removeTags.js:16)
    at e.t.<computed> (extend.js:61)
    at e.<anonymous> (removeTags.js:16)
    at e.t.<computed> (extend.js:61)
    at e.<anonymous> (removeTags.js:16)
    at e.t.<computed> (extend.js:61)
    at e.n.onsubmit (TextEditor.js:182)
    at HTMLButtonElement.H.t.<computed> (mithril.js:1286)

The error is thrown in the core Model.js library. None of the listed .js files comes from a 3rd-party-extension.

However I've disabled extensions which might influence the behavior of the page when viewing a user page - but still occurring. I disabled these: FoF Spamblock, FoF Social Profile, FoF Moderator Notes, ReFlar Level Ranks, Suspend, Color Codes, Terms.

akizor commented 4 years ago

I have the same issue on a fresh flarum install. I tried to downgrade the core to beta.11 but no luck, the error is still there.

TypeError: t is undefined Model.js:303:6
    getIdentifier Model.js:303
    map self-hosted:251
    save Model.js:142
    onsubmit PrivateDiscussionComposer.js:30
    <anonymous> self-hosted:874
    It removeTags.js:16
    e extend.js:61
    <anonymous> self-hosted:874
    It removeTags.js:16
    e extend.js:61
    <anonymous> self-hosted:874
    It removeTags.js:16
    e extend.js:61
    <anonymous> self-hosted:876
    onsubmit TextEditor.js:182
    <anonymous> self-hosted:876
    H/t[e]< mithril.js:1286
Flarum core 0.1.0-beta.12
PHP version: 7.3.11
Loaded extensions: Core, phpdbg_webhelper, date, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dba, dom, hash, fileinfo, filter, ftp, gd, gettext, gmp, SPL, iconv, intl, json, ldap, mbstring, session, standard, odbc, pcntl, mysqlnd, PDO, pdo_dblib, pdo_mysql, PDO_ODBC, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, pspell, readline, Reflection, mysqli, shmop, SimpleXML, soap, sockets, sodium, exif, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, Zend OPcache
+----------------------+----------------+--------+
| Flarum Extensions    |                |        |
+----------------------+----------------+--------+
| ID                   | Version        | Commit |
+----------------------+----------------+--------+
| flarum-approval      | v0.1.0-beta.12 |        |
| flarum-bbcode        | v0.1.0-beta.12 |        |
| flarum-emoji         | v0.1.0-beta.12 |        |
| flarum-lang-english  | v0.1.0-beta.12 |        |
| flarum-flags         | v0.1.0-beta.12 |        |
| flarum-likes         | v0.1.0-beta.12 |        |
| flarum-lock          | v0.1.0-beta.12 |        |
| flarum-markdown      | v0.1.0-beta.12 |        |
| flarum-mentions      | v0.1.0-beta.12 |        |
| flarum-statistics    | v0.1.0-beta.12 |        |
| flarum-sticky        | v0.1.0-beta.12 |        |
| flarum-subscriptions | v0.1.0-beta.12 |        |
| flarum-suspend       | v0.1.0-beta.12 |        |
| flarum-tags          | v0.1.0-beta.12 |        |
| fof-byobu            | 0.4.4          |        |
| fof-upload           | 0.8.3          |        |
+----------------------+----------------+--------+

Tried to disable extensions, but no luck whatsoever.

akizor commented 4 years ago

Found something, messaging works when using "fof/byobu": "0.4.1",. Error is gone.

askvortsov1 commented 4 years ago

I (believe) I was able to find the cause of this: if the user sets a primary tag to force discussions into, but that tag doesn't exist, this error occurs.

patschi commented 4 years ago

You're right, @askvortsov1! Once defining a existing primary tag, it works without any issues. Thanks a lot for pointing that out!

clarkwinkelmann commented 4 years ago

I did some tests and I replicated @askvortsov1 report. It was due to an invalid slug.

I prepared this PR to improve the error message, anyone wants to take a look before I merge ? https://github.com/FriendsOfFlarum/byobu/pull/105

I don't see any proper way to "fix" this. All we can do is at least provide a useful error. With my PR the error would look like this:

image

Another, maybe better option, would be to set the tag server-side, that way we can return a validation message that says the tag was invalid (currently the tag is set client-side, and only validated server-side)

imorland commented 4 years ago

Nice one @clarkwinkelmann

I think this is a good interim solution to the problem. Longer term, I think a solution that uses a drop-down picker would be useful.