초대 페이지 오류 - "undefined의 속성을 읽을 수 없습니다('slice')"

최신 안정판에서 /u/user_name/invited/pending 페이지의 “초대 링크 생성” 버튼을 클릭하면 JavaScript 오류가 발생합니다.

콘솔에는 다음과 같은 내용이 표시됩니다:

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

초대 객체가 서버에서 invite_key가 채워지기 전에 렌더링되면 invite_key가 undefined 상태가 되어, 아무것도 없는 값에 .slice()를 사용하려고 할 때 크래시가 발생합니다.

invite.js의 shortKey 함수는 초대 키를 줄이는 작업을 수행합니다:

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

메타 서버에서는 재현할 수 없으므로, 제 서버나 네트워크 속도가 느리기 때문일 수도 있습니다. 하지만 사용 전에 키가 존재하는지 확인하는 것이 문제를 해결하는 것 같습니다:

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}}

I think this would be fine as a PR provided it is localized.

Still a bit confused about where we are populating Invite with a half full object, but it is better than failing and seems correct to me.

I wonder if it’s been fixed on latest. In that case, we just need to identify the commit which fixed it, and backport it to stable.

The invite is added to the list immediately after save() but before invite_key is populated from the server. It’s still present in latest, so I opened PR #35679

1개의 좋아요