Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ async function fetchResults(
const query = input.value
if (checkCurrentQuery && state.currentQuery === query) return

state.currentQuery = query

const src = remoteInput.src
if (!src) return

Expand All @@ -99,6 +97,8 @@ async function fetchResults(
)
if (!resultsContainer) return

state.currentQuery = query

const url = new URL(src, window.location.href)
const params = new URLSearchParams(url.search)
params.append(remoteInput.getAttribute('param') || 'q', query)
Expand Down
25 changes: 25 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ describe('remote-input', function () {
results = null
})

for (const missing of ['source', 'results']) {
it(`retries an unchanged query when the missing ${missing} becomes available`, async function () {
if (missing === 'source') remoteInput.removeAttribute('src')
else results.remove()
let loads = 0
remoteInput.addEventListener('loadstart', () => loads++)
changeValue(input, 'test')
assert.equal(loads, 0)

if (missing === 'source') remoteInput.src = '/results'
else document.body.append(results)
const success = once(remoteInput, 'remote-input-success')
input.dispatchEvent(new Event('focus'))
await success
assert.equal(loads, 1)
assert.equal(
results.querySelector('ol').getAttribute('data-src'),
'/results?q=test'
)

input.dispatchEvent(new Event('focus'))
assert.equal(loads, 1)
})
}

it('emits network events in order', async function () {
const events = []
const track = (event) => events.push(event.type)
Expand Down
Loading