-
-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composebox cleanup #4773
Composebox cleanup #4773
Changes from all commits
c9f35d5
1c8aa4b
f262ac8
86dd6af
ab9eb3f
f83e05d
9393d8a
140c0c0
ec49476
09495d4
24ada87
f8f32a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* @flow strict-local */ | ||
import React from 'react'; | ||
import React, { useCallback, useContext } from 'react'; | ||
import type { Node } from 'react'; | ||
import { useIsFocused } from '@react-navigation/native'; | ||
|
||
|
@@ -17,11 +17,17 @@ import InvalidNarrow from './InvalidNarrow'; | |
import { fetchMessagesInNarrow } from '../message/fetchActions'; | ||
import ComposeBox from '../compose/ComposeBox'; | ||
import UnreadNotice from './UnreadNotice'; | ||
import { canSendToNarrow } from '../utils/narrow'; | ||
import { canSendToNarrow, caseNarrowDefault, keyFromNarrow } from '../utils/narrow'; | ||
import { getLoading, getSession } from '../directSelectors'; | ||
import { getFetchingForNarrow } from './fetchingSelectors'; | ||
import { getShownMessagesForNarrow, isNarrowValid as getIsNarrowValid } from './narrowsSelectors'; | ||
import { getFirstUnreadIdInNarrow } from '../message/messageSelectors'; | ||
import { getDraftForNarrow } from '../drafts/draftsSelectors'; | ||
import { addToOutbox } from '../actions'; | ||
import { getAuth, getCaughtUpForNarrow } from '../selectors'; | ||
import { showErrorAlert } from '../utils/info'; | ||
import { TranslationContext } from '../boot/TranslationProvider'; | ||
import * as api from '../api'; | ||
|
||
type Props = $ReadOnly<{| | ||
navigation: AppNavigationProp<'chat'>, | ||
|
@@ -103,10 +109,13 @@ export default function ChatScreen(props: Props): Node { | |
const { backgroundColor } = React.useContext(ThemeContext); | ||
|
||
const { narrow, editMessage } = route.params; | ||
const setEditMessage = (value: EditMessage | null) => | ||
navigation.setParams({ editMessage: value }); | ||
const setEditMessage = useCallback( | ||
(value: EditMessage | null) => navigation.setParams({ editMessage: value }), | ||
[navigation], | ||
); | ||
|
||
const isNarrowValid = useSelector(state => getIsNarrowValid(state, narrow)); | ||
const draft = useSelector(state => getDraftForNarrow(state, narrow)); | ||
|
||
const { | ||
fetchError, | ||
|
@@ -120,6 +129,43 @@ export default function ChatScreen(props: Props): Node { | |
const sayNoMessages = haveNoMessages && !isFetching; | ||
const showComposeBox = canSendToNarrow(narrow) && !showMessagePlaceholders; | ||
|
||
const auth = useSelector(getAuth); | ||
const dispatch = useDispatch(); | ||
const caughtUp = useSelector(state => getCaughtUpForNarrow(state, narrow)); | ||
const _ = useContext(TranslationContext); | ||
|
||
const sendCallback = useCallback( | ||
(message: string, destinationNarrow: Narrow) => { | ||
if (editMessage) { | ||
const content = editMessage.content !== message ? message : undefined; | ||
const subject = caseNarrowDefault( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the change to start using Ah, looking again: possibly this was a small rebase error? 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, I think I had this in there the whole time, and I agree that the commit doesn't describe that. The reason that it's needed is that the previous code could look directly at the I've added a commit to make that change in the original code. |
||
destinationNarrow, | ||
{ topic: (stream, topic) => (topic !== editMessage.topic ? topic : undefined) }, | ||
() => undefined, | ||
); | ||
|
||
if ( | ||
(content !== undefined && content !== '') | ||
|| (subject !== undefined && subject !== '') | ||
) { | ||
api.updateMessage(auth, { content, subject }, editMessage.id).catch(error => { | ||
showErrorAlert(_('Failed to edit message'), error.message); | ||
}); | ||
} | ||
|
||
setEditMessage(null); | ||
} else { | ||
if (!caughtUp.newer) { | ||
showErrorAlert(_('Failed to send message')); | ||
return; | ||
} | ||
|
||
dispatch(addToOutbox(destinationNarrow, message)); | ||
gnprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}, | ||
[_, auth, caughtUp.newer, dispatch, editMessage, setEditMessage], | ||
); | ||
|
||
return ( | ||
<KeyboardAvoider style={[componentStyles.screen, { backgroundColor }]} behavior="padding"> | ||
<ChatNavBar narrow={narrow} editMessage={editMessage} /> | ||
|
@@ -147,8 +193,12 @@ export default function ChatScreen(props: Props): Node { | |
{showComposeBox && ( | ||
<ComposeBox | ||
narrow={narrow} | ||
editMessage={editMessage} | ||
completeEditMessage={() => setEditMessage(null)} | ||
isEditing={editMessage !== null} | ||
initialTopic={editMessage ? editMessage.topic : undefined} | ||
initialMessage={editMessage ? editMessage.content : draft} | ||
onSend={sendCallback} | ||
autoFocusMessage={editMessage !== null} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think there might be some more details in your head that could helpfully be written down? 😄 I'm imagining coming to this in the future while trying to work out why the change was made (e.g., because it's relevant to some bug that we find), and feeling like there should be an answer but I'm not quite finding it. Was the regression introduced earlier in the PR? If so, let's look for a way to not introduce it in the first place. If that's not going to work (e.g., because it forces us to obscure more than we clarify), then maybe a good workaround is to minimize the number of commits in which the regression is active, and fence it off clearly (the commit that introduces the regression and the commit that fixes it both mention each other and how far apart they are). I took this approach once, in the consecutive commits cc0126d and 3fa7a7f, where the regression was a small UI thing and I felt each change needed some breathing room to help it be understood. If the regression is already in Then, I'm interested in knowing what the regression was and why this is the right fix for it. 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding was that this was a regression when switching to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Cool. It seems very plausible that the regression, whatever it was, would have been introduced in the Also let's link to the CZO discussion where I mentioned the Elsewhere in this review, I floated the idea of lumping into this commit the change to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also mention the 100+ appearances of an error, in a loop, that seem to get resolved in this commit 🎉: #4773 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, glad to start having Also, as I look again, I'm glad to have the mention of the "Warning: Cannot update a component from inside…" fix in the commit message, since this sure seems to be the commit that changes that behavior for the better. But while it's nice (and potentially really helpful for responding to bug reports) to know that the specific behavior is improved, it's also true that we didn't end up with a really precise diagnosis, and I think we should mention that. As-is, I think it's possible for someone to follow the link after "See the CZO thread" in hopes of finding a diagnosis, and they'll be disappointed and possibly confused when they don't find one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment about this in the commit message. I don't think it's as mysterious as our initial conversation made it out to be — there was some logic in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Understood. 🙂 But we depend heavily on reading a clear commit history, and I think I've mentioned elsewhere that the Also, I think explaining these prop changes does more than just answer why we made them: it clarifies a bit the limits of what we considered. Without these explanations, I think someone in the future is more likely to assume that we deduced that these changes were all we had to do toward replicating the logic in |
||
key={keyFromNarrow(narrow) + (editMessage?.id.toString() ?? 'noedit')} | ||
/> | ||
)} | ||
</KeyboardAvoider> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,9 @@ import { ThemeContext } from '../styles'; | |
import type { | ||
Auth, | ||
Narrow, | ||
EditMessage, | ||
InputSelection, | ||
UserOrBot, | ||
Dispatch, | ||
CaughtUp, | ||
GetText, | ||
Subscription, | ||
Stream, | ||
|
@@ -28,39 +26,33 @@ import type { | |
} from '../types'; | ||
import { connect } from '../react-redux'; | ||
import { withGetText } from '../boot/TranslationProvider'; | ||
import { addToOutbox, draftUpdate, sendTypingStart, sendTypingStop } from '../actions'; | ||
import * as api from '../api'; | ||
import { draftUpdate, sendTypingStart, sendTypingStop } from '../actions'; | ||
import { FloatingActionButton, Input } from '../common'; | ||
import { showErrorAlert, showToast } from '../utils/info'; | ||
import { showToast } from '../utils/info'; | ||
import { IconDone, IconSend } from '../common/Icons'; | ||
import { | ||
isStreamNarrow, | ||
isStreamOrTopicNarrow, | ||
isTopicNarrow, | ||
streamNameOfNarrow, | ||
topicNarrow, | ||
topicOfNarrow, | ||
} from '../utils/narrow'; | ||
import ComposeMenu from './ComposeMenu'; | ||
import getComposeInputPlaceholder from './getComposeInputPlaceholder'; | ||
import NotSubscribed from '../message/NotSubscribed'; | ||
import AnnouncementOnly from '../message/AnnouncementOnly'; | ||
import MentionWarnings from './MentionWarnings'; | ||
|
||
import { | ||
getAuth, | ||
getIsAdmin, | ||
getLastMessageTopic, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This seems like it'd be pretty easy to do, with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sadly not — this is referring to when you go and tap on the "Message" input box, it should actually focus the topic input box, but we don't want to |
||
getCaughtUpForNarrow, | ||
getStreamInNarrow, | ||
getVideoChatProvider, | ||
} from '../selectors'; | ||
import { getAuth, getIsAdmin, getStreamInNarrow, getVideoChatProvider } from '../selectors'; | ||
import { | ||
getIsActiveStreamSubscribed, | ||
getIsActiveStreamAnnouncementOnly, | ||
} from '../subscriptions/subscriptionSelectors'; | ||
import { getDraftForNarrow } from '../drafts/draftsSelectors'; | ||
import TopicAutocomplete from '../autocomplete/TopicAutocomplete'; | ||
import AutocompleteView from '../autocomplete/AutocompleteView'; | ||
import { getAllUsersById, getOwnUserId } from '../users/userSelectors'; | ||
import * as api from '../api'; | ||
|
||
type SelectorProps = {| | ||
auth: Auth, | ||
|
@@ -69,21 +61,35 @@ type SelectorProps = {| | |
isAdmin: boolean, | ||
isAnnouncementOnly: boolean, | ||
isSubscribed: boolean, | ||
draft: string, | ||
lastMessageTopic: string, | ||
caughtUp: CaughtUp, | ||
videoChatProvider: VideoChatProvider | null, | ||
stream: Subscription | {| ...Stream, in_home_view: boolean |}, | ||
|}; | ||
|
||
type OuterProps = $ReadOnly<{| | ||
narrow: Narrow, | ||
editMessage: EditMessage | null, | ||
completeEditMessage: () => void, | ||
|
||
onSend: (string, Narrow) => void, | ||
|
||
isEditing: boolean, | ||
|
||
/** The contents of the message that the ComposeBox should contain when it's first rendered */ | ||
initialMessage?: string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The component so far hasn't set a good example of this, of course, but: let's add some jsdoc for at least the props we add, to be explicit about That'll be a clear sign facing callers (well, the one caller) so they can be sure to use It'll also be a clear sign facing inward, toward the implementation, so it can develop without breaking any expectations that the callers (caller) might have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done :) |
||
/** The topic of the message that the ComposeBox should contain when it's first rendered */ | ||
initialTopic?: string, | ||
|
||
/** Whether the topic input box should auto-foucs when the component renders. | ||
* | ||
* Passed through to the TextInput's autofocus prop. */ | ||
autoFocusTopic?: boolean, | ||
/** Whether the message input box should auto-foucs when the component renders. | ||
* | ||
* Passed through to the TextInput's autofocus prop. */ | ||
autoFocusMessage?: boolean, | ||
|}>; | ||
|
||
type Props = $ReadOnly<{| | ||
...OuterProps, | ||
...SelectorProps, | ||
|
||
// From 'withGetText' | ||
_: GetText, | ||
|
@@ -155,8 +161,10 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
isFocused: false, | ||
isMenuExpanded: false, | ||
height: 20, | ||
topic: this.props.lastMessageTopic, | ||
message: this.props.draft, | ||
topic: | ||
this.props.initialTopic | ||
?? (isTopicNarrow(this.props.narrow) ? topicOfNarrow(this.props.narrow) : ''), | ||
message: this.props.initialMessage ?? '', | ||
Comment on lines
+164
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This diff is doing a couple of unrelated things in addition to the point of the commit:
In particular it's switching the It'd be cleanest to have the earlier commit that introduces this logic use |
||
selection: { start: 0, end: 0 }, | ||
numUploading: 0, | ||
}; | ||
|
@@ -174,8 +182,8 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
}; | ||
|
||
getCanSelectTopic = () => { | ||
const { editMessage, narrow } = this.props; | ||
if (editMessage) { | ||
const { isEditing, narrow } = this.props; | ||
if (isEditing) { | ||
return isStreamOrTopicNarrow(narrow); | ||
} | ||
if (!isStreamNarrow(narrow)) { | ||
|
@@ -291,9 +299,11 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
|
||
handleMessageChange = (message: string) => { | ||
this.setState({ message, isMenuExpanded: false }); | ||
const { dispatch, narrow } = this.props; | ||
const { dispatch, isEditing, narrow } = this.props; | ||
dispatch(sendTypingStart(narrow)); | ||
dispatch(draftUpdate(narrow, message)); | ||
if (!isEditing) { | ||
dispatch(draftUpdate(narrow, message)); | ||
} | ||
}; | ||
|
||
// See JSDoc on 'onAutocomplete' in 'AutocompleteView.js'. | ||
|
@@ -320,13 +330,11 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
}; | ||
|
||
handleMessageFocus = () => { | ||
this.setState((state, { lastMessageTopic }) => ({ | ||
...state, | ||
topic: state.topic || lastMessageTopic, | ||
gnprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.setState({ | ||
isMessageFocused: true, | ||
isFocused: true, | ||
isMenuExpanded: false, | ||
})); | ||
}); | ||
}; | ||
|
||
handleMessageBlur = () => { | ||
|
@@ -362,8 +370,8 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
}; | ||
|
||
getDestinationNarrow = (): Narrow => { | ||
const { narrow } = this.props; | ||
if (isStreamNarrow(narrow)) { | ||
const { narrow, isEditing } = this.props; | ||
if (isStreamNarrow(narrow) || (isTopicNarrow(narrow) && isEditing)) { | ||
const streamName = streamNameOfNarrow(narrow); | ||
const topic = this.state.topic.trim(); | ||
return topicNarrow(streamName, topic || '(no topic)'); | ||
|
@@ -372,15 +380,11 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
}; | ||
|
||
handleSend = () => { | ||
const { dispatch, narrow, caughtUp, _ } = this.props; | ||
const { dispatch } = this.props; | ||
const { message } = this.state; | ||
const narrow = this.getDestinationNarrow(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This change is good, but the commit message should mention that all of this is in the future when we start sending typing notifications for stream messages at all; i.e., this is a latent bug, lying in wait for when we add that feature. Otherwise it's confusing for someone who knows that we only send typing notifications for PMs, as they try to figure out what scenario the commit message is talking about in which we're sending typing notifications and then the destination narrow changes. Hmm, in fact: I think even in that future, this won't at least primarily be about the destination narrow changing. The typical case where … Hmm and actually, looking at the implementation of Does that affect any of the other changes in this branch? I feel like there were some refactorings that relied on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I was seeing #4830, which reproduces on master :/ I believe that the code as it is now is no more incorrect than it was previously, but I obviously could be missing something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That fix looks good, thanks! (Modulo the thread at #4773 (comment) .) |
||
|
||
if (!caughtUp.newer) { | ||
showErrorAlert(_('Failed to send message')); | ||
return; | ||
} | ||
Comment on lines
-378
to
-381
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this reintroduce #3800? If not, why not? In any case I don't think this benefits from being rolled into a long cleanup series like this one -- it's entirely about a behavior change, not anything to do with cleaning up the code. Better to have its own PR thread, to avoid adding complexity to this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does — I hadn't realized this history of this. I had thought that something about this PR made the symptoms described in #mobile > Failed to send on Android worse, but looking at it again, I don't think that's the case. I've removed this commit. |
||
|
||
dispatch(addToOutbox(this.getDestinationNarrow(), message)); | ||
this.props.onSend(message, narrow); | ||
|
||
this.setMessageInputValue(''); | ||
|
||
|
@@ -391,41 +395,6 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
dispatch(sendTypingStop(narrow)); | ||
}; | ||
|
||
handleEdit = () => { | ||
const { auth, editMessage, completeEditMessage, _ } = this.props; | ||
if (!editMessage) { | ||
throw new Error('expected editMessage'); | ||
} | ||
const { message, topic } = this.state; | ||
const content = editMessage.content !== message ? message : undefined; | ||
const subject = topic !== editMessage.topic ? topic : undefined; | ||
if ((content !== undefined && content !== '') || (subject !== undefined && subject !== '')) { | ||
api.updateMessage(auth, { content, subject }, editMessage.id).catch(error => { | ||
showErrorAlert(_('Failed to edit message'), error.message); | ||
}); | ||
} | ||
completeEditMessage(); | ||
if (this.messageInputRef.current !== null) { | ||
// `.current` is not type-checked; see definition. | ||
this.messageInputRef.current.blur(); | ||
} | ||
}; | ||
|
||
UNSAFE_componentWillReceiveProps(nextProps: Props) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This isn't correct: it doesn't cause the ComposeBox to rerender in the normal sense (that
That's how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a nice explanation of the strategy we've chosen, which I linked to in the CZO discussion (see the heading "Recommendation: Fully uncontrolled component with a key"). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation! Reworded the commit. |
||
if (nextProps.editMessage !== this.props.editMessage) { | ||
const topic = nextProps.editMessage | ||
? nextProps.editMessage.topic | ||
: nextProps.lastMessageTopic; | ||
const message = nextProps.editMessage ? nextProps.editMessage.content : ''; | ||
this.setMessageInputValue(message); | ||
this.setTopicInputValue(topic); | ||
if (this.messageInputRef.current !== null) { | ||
// `.current` is not type-checked; see definition. | ||
this.messageInputRef.current.focus(); | ||
} | ||
} | ||
} | ||
Comment on lines
-414
to
-427
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎊 Glad to be getting rid of this code 😄 -- not only is it using an API labeled "UNSAFE", but the logic inside it is kind of tangly and dubious. |
||
|
||
inputMarginPadding = { | ||
paddingHorizontal: 8, | ||
paddingVertical: Platform.select({ | ||
|
@@ -477,7 +446,7 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
ownUserId, | ||
narrow, | ||
allUsersById, | ||
editMessage, | ||
isEditing, | ||
insets, | ||
isAdmin, | ||
isAnnouncementOnly, | ||
|
@@ -533,6 +502,7 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
underlineColorAndroid="transparent" | ||
placeholder="Topic" | ||
defaultValue={topic} | ||
autoFocus={this.props.autoFocusTopic} | ||
selectTextOnFocus | ||
textInputRef={this.topicInputRef} | ||
onChangeText={this.handleTopicChange} | ||
|
@@ -550,6 +520,7 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
underlineColorAndroid="transparent" | ||
placeholder={placeholder} | ||
defaultValue={message} | ||
autoFocus={this.props.autoFocusMessage} | ||
textInputRef={this.messageInputRef} | ||
onBlur={this.handleMessageBlur} | ||
onChangeText={this.handleMessageChange} | ||
|
@@ -561,10 +532,10 @@ class ComposeBoxInner extends PureComponent<Props, State> { | |
<FloatingActionButton | ||
accessibilityLabel="Send message" | ||
style={this.styles.composeSendButton} | ||
Icon={editMessage === null ? IconSend : IconDone} | ||
Icon={isEditing ? IconDone : IconSend} | ||
size={32} | ||
disabled={message.trim().length === 0 || this.state.numUploading > 0} | ||
onPress={editMessage === null ? this.handleSend : this.handleEdit} | ||
onPress={this.handleSend} | ||
gnprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
</View> | ||
</View> | ||
|
@@ -580,9 +551,6 @@ const ComposeBox: ComponentType<OuterProps> = compose( | |
isAdmin: getIsAdmin(state), | ||
isAnnouncementOnly: getIsActiveStreamAnnouncementOnly(state, props.narrow), | ||
isSubscribed: getIsActiveStreamSubscribed(state, props.narrow), | ||
draft: getDraftForNarrow(state, props.narrow), | ||
lastMessageTopic: getLastMessageTopic(state, props.narrow), | ||
gnprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
caughtUp: getCaughtUpForNarrow(state, props.narrow), | ||
stream: getStreamInNarrow(state, props.narrow), | ||
videoChatProvider: getVideoChatProvider(state), | ||
})), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, could you say more about how adding
defaultTopic
anddefaultMessage
lets us get rid ofUNSAFE_componentWillReceiveProps
? What problems might we run into if we tried to get rid of it before adding those props? The changes look orthogonal to me, but I might be missing something. Or, if there would be problems, how about putting it after?It'd be good to keep the commit that removes
UNSAFE_componentWillReceiveProps
as focused as possible. I do think thekey
approach is probably the right one, for reasons I've mentioned on CZO, but it's not a small change: the component will start getting completely unmounted and remounted, losing all of its state; that'll happen wheneverkey
changes.If it does introduce a bug, it'll probably be a puzzling one, the kind that might be easiest to find with a
git bisect
, and we'll want to help that investigation go smoothly. Also, I think it would be helpful for that commit to link to the discussion of thekey
solution, like https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Next.20steps.20for.20.60ComposeBox.60/near/1160876.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, here's one behavior change I've just found, and it's a nice one! Just before this commit, I get the following (and also on
master
I get something that looks the same) when I start editing a message, along with lots of lag. It goes away at this commit; I suspect that's because of removingUNSAFE_componentWillReceiveProps
. I read a bit about the error message and didn't come up with much (facebook/react#18178) and I decided not to look further; we were using something markedUNSAFE
after all, so it seems like not-doing-that is a fine fix, seeing as it seems to work. 🤷There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct, these are orthogonal. I've refactored the commits to avoid mixing them up.