polaris_view_components 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fec4405e8b1c604811d7bf69ece811a57fa31447754fe6a3f67cac17fc5c9ed
4
- data.tar.gz: d670c3c83b34ec0bff77066c94ffbe0eca60530985f6b3d44589108c740f071e
3
+ metadata.gz: 2556310257a7b7bc5360830ea381c0619787796c347ba9414e7ff98826f6e19b
4
+ data.tar.gz: 3120e335bb52aca18bf9e7e5a00b773a47b02a74777bf3467204847604f7f2f7
5
5
  SHA512:
6
- metadata.gz: 29daf7afd8f7a06ec3b9c41530a97b02bdd2accc663f911133ab413d8682c06d503a697afc0ea28719084fc9498d7a04cf98ac61fcdab3632f0c299a451006b2
7
- data.tar.gz: 0120f2a3d552796b7eeb7ef4de1d38fb7d8862865e776d96548abfaacb8b95879b0a29ed964006ad8ca7c8b00cd865beeec40333bab665371c05af604033bcb9
6
+ metadata.gz: d6e016aaaac91d443b9d9846b4d49748819a436ba43f7f9e4d2acfd4d3cf9435d54591a17c143b8f76f8d1d85257ff0387f19c69bd7db769d5419c6acaaa886a
7
+ data.tar.gz: f88419ccb82a51a2963ed40356c731ab279bbb5892585e27429cdd619ffb43115a6f04180ca6f00299bc026d4ecb424007ae8e1e691859909f6a3839b76b2595
@@ -44,6 +44,10 @@ export default class extends Controller {
44
44
  }
45
45
 
46
46
  onInputChange = debounce(() => {
47
+ // The element may have been removed (e.g. replaced by a Turbo Stream)
48
+ // before the debounced callback fires.
49
+ if (!this.element.isConnected) return
50
+
47
51
  if (this.isRemote) {
48
52
  this.fetchResults()
49
53
  } else {
@@ -80,6 +84,9 @@ export default class extends Controller {
80
84
  }
81
85
 
82
86
  handleResults() {
87
+ // The popover controller is gone once the element has been disconnected.
88
+ if (!this.popoverController) return
89
+
83
90
  if (this.visibleOptions.length > 0) {
84
91
  this.hideEmptyState()
85
92
  this.popoverController.show()
@@ -119,6 +126,8 @@ export default class extends Controller {
119
126
  if (response.ok) {
120
127
  const results = await response.html
121
128
 
129
+ // Ignore responses that arrive after the element was removed from the page.
130
+ if (!this.element.isConnected) return
122
131
  if (requestId !== this.latestRequestId || query !== this.value) return
123
132
 
124
133
  this.resultsTarget.innerHTML = results
@@ -212,6 +212,7 @@ class Autocomplete extends Controller {
212
212
  this.element.dispatchEvent(changeEvent);
213
213
  }
214
214
  onInputChange=debounce((() => {
215
+ if (!this.element.isConnected) return;
215
216
  if (this.isRemote) {
216
217
  this.fetchResults();
217
218
  } else {
@@ -238,6 +239,7 @@ class Autocomplete extends Controller {
238
239
  return [ ...this.optionTargets ].filter((option => !option.classList.contains("Polaris--hidden")));
239
240
  }
240
241
  handleResults() {
242
+ if (!this.popoverController) return;
241
243
  if (this.visibleOptions.length > 0) {
242
244
  this.hideEmptyState();
243
245
  this.popoverController.show();
@@ -276,6 +278,7 @@ class Autocomplete extends Controller {
276
278
  });
277
279
  if (response.ok) {
278
280
  const results = await response.html;
281
+ if (!this.element.isConnected) return;
279
282
  if (requestId !== this.latestRequestId || query !== this.value) return;
280
283
  this.resultsTarget.innerHTML = results;
281
284
  this.handleResults();
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
2
  module ViewComponents
3
- VERSION = "4.0.0"
3
+ VERSION = "4.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polaris_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Gamble