Merge pull request #20005 from prlanzarin/u27/fix/crash-getBoundingClientRect-emojirain

[2.7] fix(reactions): crash when interactionsButton coords are absent
This commit is contained in:
Anton Georgiev 2024-04-12 15:13:33 -04:00 committed by GitHub
commit fda4a5a2ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View File

@ -1,6 +1,7 @@
import React, { useRef, useState, useEffect } from 'react'; import React, { useRef, useState, useEffect } from 'react';
import Settings from '/imports/ui/services/settings'; import Settings from '/imports/ui/services/settings';
import Service from './service'; import Service from './service';
import logger from '/imports/startup/client/logger';
const EmojiRain = ({ reactions }) => { const EmojiRain = ({ reactions }) => {
const containerRef = useRef(null); const containerRef = useRef(null);
@ -12,9 +13,16 @@ const EmojiRain = ({ reactions }) => {
const { animations } = Settings.application; const { animations } = Settings.application;
function createEmojiRain(emoji) { function createEmojiRain(emoji) {
const coord = Service.getInteractionsButtonCoordenates(); const coord = Service.getInteractionsButtonCoordinates();
const flyingEmojis = []; const flyingEmojis = [];
if (coord == null) {
logger.warn({
logCode: 'interactions_emoji_rain_no_coord',
}, 'No coordinates for interactions button, skipping emoji rain');
return;
}
for (i = 0; i < NUMBER_OF_EMOJIS; i++) { for (i = 0; i < NUMBER_OF_EMOJIS; i++) {
const initialPosition = { const initialPosition = {
x: coord.x + coord.width / 8, x: coord.x + coord.width / 8,

View File

@ -1,9 +1,13 @@
const getInteractionsButtonCoordenates = () => { const getInteractionsButtonCoordinates = () => {
const el = document.getElementById('interactionsButton'); const el = document.getElementById('interactionsButton');
const coordenada = el.getBoundingClientRect();
return coordenada; if (!el) return null;
const coordinate = el.getBoundingClientRect();
return coordinate;
}; };
export default { export default {
getInteractionsButtonCoordenates, getInteractionsButtonCoordinates,
}; };