Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 70d4ac3

Browse files
authored
Merge pull request #4718 from brave/fix/urlbar-lag
Potential fix for URL bar lag, 2nd try
2 parents 7c78c9a + 083c89b commit 70d4ac3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

js/components/urlBar.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class UrlBar extends ImmutableComponent {
4848
return windowStore.getFrame(this.props.activeFrameKey)
4949
}
5050

51-
isActive () {
51+
get isActive () {
5252
return this.props.urlbar.get('active')
5353
}
5454

@@ -285,13 +285,18 @@ class UrlBar extends ImmutableComponent {
285285
}
286286

287287
componentDidUpdate (prevProps) {
288-
this.updateDOM()
289288
// Select the part of the URL which was an autocomplete suffix.
290-
if (this.urlInput && this.props.locationValueSuffix.length > 0) {
291-
const len = this.urlInput.value.length
289+
if (this.urlInput && this.props.locationValueSuffix.length > 0 &&
290+
this.props.urlbar.get('location') !== prevProps.urlbar.get('location')) {
292291
const suffixLen = this.props.locationValueSuffix.length
292+
this.urlInput.value = this.locationValue + this.props.locationValueSuffix
293+
const len = this.urlInput.value.length
293294
this.urlInput.setSelectionRange(len - suffixLen, len)
294295
}
296+
if (this.isSelected() !== prevProps.urlbar.get('selected') ||
297+
this.isFocused() !== prevProps.urlbar.get('focused')) {
298+
this.updateDOM()
299+
}
295300
}
296301

297302
get hostValue () {
@@ -370,6 +375,9 @@ class UrlBar extends ImmutableComponent {
370375
}
371376

372377
render () {
378+
const value = !this.isActive
379+
? this.locationValue + this.props.locationValueSuffix
380+
: undefined
373381
return <form
374382
className='urlbarForm'
375383
action='#'
@@ -412,10 +420,10 @@ class UrlBar extends ImmutableComponent {
412420
onFocus={this.onFocus}
413421
onBlur={this.onBlur}
414422
onKeyDown={this.onKeyDown}
415-
onChange={this.onChange}
423+
onKeyUp={this.onChange}
416424
onClick={this.onClick}
417425
onContextMenu={this.onContextMenu}
418-
value={this.locationValue + this.props.locationValueSuffix}
426+
value={value}
419427
data-l10n-id='urlbar'
420428
className={cx({
421429
insecure: !this.props.isSecure && this.props.loading === false && !this.isHTTPPage,

0 commit comments

Comments
 (0)