Skip to content

Commit b86281b

Browse files
committed
Fixed search initialization (7.3.2 regression)
1 parent 24197fa commit b86281b

File tree

6 files changed

+41
-28
lines changed

6 files changed

+41
-28
lines changed

material/assets/javascripts/bundle.f89c2efe.min.js renamed to material/assets/javascripts/bundle.1e84347e.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/assets/javascripts/bundle.f89c2efe.min.js.map renamed to material/assets/javascripts/bundle.1e84347e.min.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ <h1>{{ page.title | d(config.site_name, true)}}</h1>
225225
</script>
226226
{% endblock %}
227227
{% block scripts %}
228-
<script src="{{ 'assets/javascripts/bundle.f89c2efe.min.js' | url }}"></script>
228+
<script src="{{ 'assets/javascripts/bundle.1e84347e.min.js' | url }}"></script>
229229
{% for path in config["extra_javascript"] %}
230230
<script src="{{ path | url }}"></script>
231231
{% endfor %}

src/assets/javascripts/components/search/query/index.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
filter,
3535
finalize,
3636
map,
37+
shareReplay,
38+
startWith,
3739
take,
3840
takeLast,
3941
takeUntil,
@@ -92,36 +94,43 @@ export function watchSearchQuery(
9294
): Observable<SearchQuery> {
9395
const fn = __search?.transform || defaultTransform
9496

97+
/* Immediately show search dialog */
98+
const { searchParams } = getLocation()
99+
if (searchParams.has("q"))
100+
setToggle("search", true)
101+
102+
/* Intercept query parameter (deep link) */
103+
const param$ = rx$
104+
.pipe(
105+
filter(isSearchReadyMessage),
106+
take(1),
107+
map(() => searchParams.get("q") || "")
108+
)
109+
110+
/* Set query from parameter */
111+
param$.subscribe(value => { // TODO: not ideal - find a better way
112+
if (value)
113+
el.value = value
114+
})
115+
95116
/* Intercept focus and input events */
96117
const focus$ = watchElementFocus(el)
97118
const value$ = merge(
98119
fromEvent(el, "keyup"),
99-
fromEvent(el, "focus").pipe(delay(1))
120+
fromEvent(el, "focus").pipe(delay(1)),
121+
param$
100122
)
101123
.pipe(
102124
map(() => fn(el.value)),
103-
distinctUntilChanged()
125+
startWith(""),
126+
distinctUntilChanged(),
104127
)
105128

106-
/* Intercept deep links */
107-
const location = getLocation()
108-
if (location.searchParams.has("q")) {
109-
setToggle("search", true)
110-
rx$
111-
.pipe(
112-
filter(isSearchReadyMessage),
113-
take(1)
114-
)
115-
.subscribe(() => {
116-
el.value = location.searchParams.get("q")!
117-
setElementFocus(el)
118-
})
119-
}
120-
121129
/* Combine into single observable */
122130
return combineLatest([value$, focus$])
123131
.pipe(
124-
map(([value, focus]) => ({ value, focus }))
132+
map(([value, focus]) => ({ value, focus })),
133+
shareReplay(1)
125134
)
126135
}
127136

src/assets/javascripts/components/search/result/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function mountSearchResult(
102102
const meta = getElementOrThrow(":scope > :first-child", el)
103103
const list = getElementOrThrow(":scope > :last-child", el)
104104

105-
/* Update search result metadata when ready */
105+
/* Wait until search is ready */
106106
const ready$ = rx$
107107
.pipe(
108108
filter(isSearchReadyMessage),

src/assets/javascripts/components/search/suggest/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import {
2424
Observable,
2525
Subject,
2626
asyncScheduler,
27-
fromEvent
27+
fromEvent,
28+
merge
2829
} from "rxjs"
2930
import {
3031
combineLatestWith,
@@ -88,7 +89,10 @@ export function mountSearchSuggest(
8889

8990
/* Retrieve query component and track all changes */
9091
const query = getComponentElement("search-query")
91-
const query$ = fromEvent(query, "keydown")
92+
const query$ = merge(
93+
fromEvent(query, "keydown"),
94+
fromEvent(query, "focus")
95+
)
9296
.pipe(
9397
observeOn(asyncScheduler),
9498
map(() => query.value),

0 commit comments

Comments
 (0)