Skip to content

Commit 9b9d4f7

Browse files
authoredMar 26, 2025··
Merge pull request #4564 from tloncorp/po/tlon-3852-fix-issue-with-tall-tweets-not-loading
embeds: fix issue with tall tweets not loading, and weird loading height issue
2 parents 16b427f + fecefaf commit 9b9d4f7

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed
 

‎packages/app/ui/components/Embed/EmbedWebView.tsx

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createDevLogger } from '@tloncorp/shared';
12
import { LoadingSpinner } from '@tloncorp/ui';
23
import {
34
memo,
@@ -20,6 +21,8 @@ import { View, getTokenValue, useTheme } from 'tamagui';
2021
import { useIsDarkTheme } from '../../utils';
2122
import { EmbedProviderConfig } from './providers';
2223

24+
const logger = createDevLogger('EmbedWebView', false);
25+
2326
const IS_ANDROID = Platform.OS === 'android';
2427
const ANDROID_LAYER_TYPE = IS_ANDROID ? 'hardware' : undefined;
2528
const ANDROID_OVERSCROLL_MODE = IS_ANDROID ? 'never' : undefined;
@@ -58,7 +61,7 @@ function webViewReducer(
5861
): WebViewState {
5962
switch (action.type) {
6063
case 'HIDE_MEDIA':
61-
return { ...state, hideTweetMedia: true };
64+
return { ...state, isLoading: false, hideTweetMedia: true };
6265
case 'SET_HEIGHT':
6366
return { ...state, webViewHeight: action.height };
6467
case 'LOADING_COMPLETE':
@@ -168,15 +171,21 @@ export const EmbedWebView = memo<EmbedWebViewProps>(
168171
(event: any) => {
169172
try {
170173
const data = JSON.parse(event.nativeEvent.data) as WebViewMessageData;
174+
logger.log('onMessageHandler', data);
171175
if (data.height && data.height > 0) {
172176
// For Twitter's initial load
173177
if (provider.name === 'Twitter' && data.loaded) {
174178
// For tall tweets that need media hiding
175179
if (data.height > maxAllowedHeight) {
180+
logger.log(
181+
'Twitter height update, loaded, too tall',
182+
data.height
183+
);
176184
// Just set the flag, don't update height yet
177185
dispatch({ type: 'HIDE_MEDIA' });
178186
} else {
179187
// For normal sized tweets, update height and complete loading in one action
188+
logger.log('Twitter height update, loaded', data.height);
180189
lastHeightRef.current = data.height;
181190
dispatch({
182191
type: 'UPDATE_HEIGHT_AND_COMPLETE',
@@ -187,7 +196,15 @@ export const EmbedWebView = memo<EmbedWebViewProps>(
187196
// For height updates from Twitter after media hiding
188197
else if (provider.name === 'Twitter' && !data.loaded) {
189198
const heightDiff = Math.abs(data.height - lastHeightRef.current);
199+
logger.log(
200+
'Twitter height update, not yet loaded, get diff',
201+
heightDiff
202+
);
190203
if (heightDiff > 25 && data.height !== lastHeightRef.current) {
204+
logger.log(
205+
'Twitter height update, not yet loaded',
206+
data.height
207+
);
191208
lastHeightRef.current = data.height;
192209
dispatch({ type: 'SET_HEIGHT', height: data.height });
193210
}
@@ -201,25 +218,26 @@ export const EmbedWebView = memo<EmbedWebViewProps>(
201218
}
202219
}
203220
} catch (e) {
204-
console.warn('Failed to parse WebView message:', e);
221+
logger.crumb('Failed to parse WebView message:', e);
205222
}
206223
},
207224
[provider.name, maxAllowedHeight]
208225
);
209226

210227
const onErrorHandler = useCallback(
211228
(event: any) => {
229+
logger.log('onErrorHandler', event);
212230
dispatch({ type: 'LOADING_COMPLETE' });
213231
const { nativeEvent } = event;
214-
console.warn('WebView error: ', nativeEvent);
232+
logger.crumb('WebView error: ', nativeEvent);
215233
onError?.(nativeEvent);
216234
},
217235
[onError]
218236
);
219237

220238
const onHttpErrorHandler = useCallback((event: any) => {
221239
const { nativeEvent } = event;
222-
console.warn(
240+
logger.crumb(
223241
`WebView received error status code: ${nativeEvent.statusCode}`
224242
);
225243
}, []);
@@ -256,7 +274,7 @@ export const EmbedWebView = memo<EmbedWebViewProps>(
256274
)}
257275
<View
258276
width={provider.defaultWidth}
259-
height={webViewHeight}
277+
height={isLoading ? 0 : webViewHeight}
260278
backgroundColor={primaryBackground}
261279
borderRadius="$s"
262280
style={containerStyle}

0 commit comments

Comments
 (0)
Please sign in to comment.