Erreur sur la page des invitations - « Impossible de lire les propriétés de undefined (lecture de 'slice') »

On the latest stable version, I see a JavaScript error when I click the “Create invite link” button at /u/user_name/invited/pending.

The console shows:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘slice’)
at h.shortKey (chunk.f105ceace2ad381ddb2f.d41d8cd9.js:241:61588)

If the invite object is rendered before invite_key is populated from the server, the invite_key is undefined and it crashes when using .slice() on nothing.

In invite.js, the shortKey function tries to shorten an invite key:

shortKey(key) {
return key.slice(0, 4) + “…”;
}

I can’t reproduce it on meta, so maybe I see it because my server or network isn’t as fast. But checking if the key exists before using it seems to resolve it:

return key ? key.slice(0, 4) + “…” : “”;

For a simple fix, is it better to post here or open a PR?

Invite key is not nullable though:

And this is iterating through model.invites:

I had a look at the code and I am not sure where partially populated code can come from, even when I added a 400ms delay on the network here I can not repro.

I think we need some sort of repro here prior to patching, that patch ends up letting people copy a broken invite link.

Thanks for looking into it and pointing that out.

Putting the delay in before_create should expose it.

I updated it to:

{{else}}
  {{icon "link"}}
+ {{#if invite.invite_key}}
    {{i18n
      "user.invited.invited_via_link"
      key=invite.shortKey
      count=invite.redemption_count
      max=invite.max_redemptions_allowed
    }}
+ {{else}}
+   <em>Generating link...</em>
+ {{/if}}
{{/if}}