achilles 1.1.3 → 1.1.4

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: ffeb9aa323be59b9a1f276b8ceb3b881747733d6e5b10ceee31149df2b49d3e8
4
- data.tar.gz: 9e0e0112177262df5c1cd7aaa5d76774d7e0b85b0b483c7d083a65d006f277d3
3
+ metadata.gz: 3e59beb8e8ab33df4ada94377c9fc2b6dd6ae961c92c763cc8c512aa0c5fa5d8
4
+ data.tar.gz: 4b11194cec10e35dc71b6a421f12bf3ad4fcfb686d379c4fb4945f20bb64ba3e
5
5
  SHA512:
6
- metadata.gz: f608ad668694d5067147da2087e07bc2ebeeb66a936cab3b267b8ebc7aaeaa9241f22f69997c7a5c9fd04fe5a0d58662b0c533afd8e6de70ec56cbbc6f9be911
7
- data.tar.gz: 6bf2ecabb1506a16c888e2d2d3fb28d9d7a2ad43af0d2fa72b558e1f00f13ac08c1e1a0528206163a4996b6e094bfa6f2888e26f4e697fcac631c2c42302607f
6
+ metadata.gz: 5987a86094329766c89ef1288865da37e5ea856a11dd84fc3e73b3f4087388fcd35675968643674b019ab8ae04039902397ac427e082c177f9f4204adc7340ee
7
+ data.tar.gz: 0b0d801e5a7f4ce5263804a13164ae33ee5ca999eac205471bed8e8a3eb649378c6323e5c920d8b77ee4bc0200e9881e5749b4fa454489aa4b1fdf2d9559bdf1
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  All notable changes to Achilles will be documented in this file.
4
4
 
5
+ ## 1.1.4
6
+
7
+ ### Performance
8
+
9
+ - Speed up component registration by querying each component's ID directly in
10
+ the browser while preserving duplicate-ID detection.
11
+ - Skip component discovery for text-only DOM updates and reconcile changes
12
+ to component markers and IDs.
13
+ - Limit Turbo Frame teardown lookups to registered components in the
14
+ outgoing frame.
15
+
5
16
  ## 1.1.3
6
17
 
7
18
  ### Fixed
data/CONTRIBUTING.md CHANGED
@@ -11,7 +11,7 @@ applications that already use the gem.
11
11
  Install dependencies:
12
12
 
13
13
  ```bash
14
- bundle install
14
+ BUNDLE_GEMFILE=gemfiles/Gemfile bundle install
15
15
  ```
16
16
 
17
17
  Run the dummy Rails app:
data/README.md CHANGED
@@ -8,9 +8,8 @@ Achilles scans the page for elements with `data-component-class`, instantiates
8
8
  the matching JavaScript class, and calls `setup` and `teardown` as Turbo renders
9
9
  new pages or new component markup is inserted.
10
10
 
11
- Use Achilles `1.1.3` for current applications. If you are upgrading an existing
12
- app, see the [upgrade index](docs/upgrading.md) and the
13
- [1.1.3 release notes](docs/releases/v1.1.3.md).
11
+ If you are upgrading an existing app, see the [upgrade index](docs/upgrading.md)
12
+ for version-specific notes.
14
13
 
15
14
  ## Why Achilles?
16
15
 
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("gemfiles/Gemfile", __dir__)
1
2
  require "bundler/setup"
2
3
 
3
4
  APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
@@ -9,7 +9,12 @@ class Observer {
9
9
  }
10
10
 
11
11
  config() {
12
- return { attributes: false, childList: true, subtree: true };
12
+ return {
13
+ attributes: true,
14
+ attributeFilter: ["id", "data-component-class"],
15
+ childList: true,
16
+ subtree: true,
17
+ };
13
18
  }
14
19
 
15
20
  start() {
@@ -22,8 +27,13 @@ class Observer {
22
27
  this._callbackScheduled = false;
23
28
  }
24
29
 
25
- domChangedCallback(mutationsList, observer) {
26
- if (this._callbackScheduled) {
30
+ domChangedCallback(mutationsList) {
31
+ if (this._callbackScheduled || !mutationsList.some((mutation) => {
32
+ // Replacing text cannot add or remove component roots.
33
+ return mutation.type !== "childList" ||
34
+ Array.from(mutation.addedNodes).some((node) => node.nodeType !== Node.TEXT_NODE) ||
35
+ Array.from(mutation.removedNodes).some((node) => node.nodeType !== Node.TEXT_NODE);
36
+ })) {
27
37
  return;
28
38
  }
29
39
 
@@ -6,7 +6,15 @@ class ComponentsRegistry {
6
6
  strictLifecycleErrors = false;
7
7
 
8
8
  matchingElementsForId(id) {
9
- return [...document.querySelectorAll('[id]')].filter((elem) => elem.id === id);
9
+ if(typeof id !== 'string')
10
+ return [];
11
+
12
+ const css = globalThis.window?.CSS;
13
+ // CSS selectors cannot preserve null characters or unpaired surrogates.
14
+ const selector = id !== '' && !/[\0\uD800-\uDFFF]/u.test(id) && typeof css?.escape === 'function'
15
+ ? `#${css.escape(id)}`
16
+ : '[id]';
17
+ return [...document.querySelectorAll(selector)].filter((elem) => elem.id === id);
10
18
  }
11
19
 
12
20
  elementForId(id) {
@@ -134,20 +142,25 @@ class ComponentsRegistry {
134
142
  if(!rootElement || typeof rootElement.contains !== 'function')
135
143
  return;
136
144
 
145
+ const candidateIds = typeof rootElement.querySelectorAll === 'function'
146
+ ? new Set([rootElement.id, ...Array.from(rootElement.querySelectorAll('[id]'), (element) => element.id)])
147
+ : null;
148
+
137
149
  Object.values(this._registeredComponents)
138
150
  .filter((component) => {
139
151
  if(component.id === AppConstants.PageComponentId)
140
152
  return false;
153
+ if(candidateIds && !candidateIds.has(component.id))
154
+ return false;
141
155
 
142
156
  let element = this.elementForId(component.id);
143
157
  return element && rootElement.contains(element);
144
158
  })
145
- .sort((firstComponent, secondComponent) => {
146
- return this.elementDepth(secondComponent.id) - this.elementDepth(firstComponent.id);
147
- })
148
- .forEach((component) => {
149
- if(this.getRegisteredComponent(component.id))
150
- this.teardownAndDeregister(component.id);
159
+ .map(({ id }) => ({ id, depth: this.elementDepth(id) }))
160
+ .sort((first, second) => second.depth - first.depth)
161
+ .forEach(({ id }) => {
162
+ if(this.getRegisteredComponent(id))
163
+ this.teardownAndDeregister(id);
151
164
  });
152
165
  }
153
166
 
@@ -0,0 +1,16 @@
1
+ # Achilles 1.1.4
2
+
3
+ Achilles now looks up each component ID directly when registering it. Duplicate
4
+ IDs still prevent registration. Text-only DOM changes no longer trigger a
5
+ component scan. On Turbo Frame replacement, Achilles finds the outgoing
6
+ components inside the frame and tears down children before their parents.
7
+
8
+ ## Upgrading
9
+
10
+ Update to `1.1.4` using the existing component markup and registration code.
11
+ Verify Turbo Frame replacement, browser history restoration, and dynamic
12
+ component insertion in your application. If you are upgrading from a version
13
+ earlier than `1.1.0`, start with the [1.1.0 upgrade guide](../upgrading-to-1.1.0.md).
14
+
15
+ - [Changelog](../../CHANGELOG.md)
16
+ - [Upgrade index](../upgrading.md)
data/docs/upgrading.md CHANGED
@@ -12,6 +12,7 @@ setup, component markup, lifecycle behavior, or public APIs.
12
12
 
13
13
  ## Release Notes
14
14
 
15
+ - [Achilles 1.1.4](releases/v1.1.4.md)
15
16
  - [Achilles 1.1.3](releases/v1.1.3.md)
16
17
  - [Achilles 1.1.2](releases/v1.1.2.md)
17
18
  - [Achilles 1.1.1](releases/v1.1.1.md)
@@ -1,3 +1,3 @@
1
1
  module Achilles
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: achilles
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jey Geethan
@@ -93,6 +93,7 @@ files:
93
93
  - docs/releases/v1.1.1.md
94
94
  - docs/releases/v1.1.2.md
95
95
  - docs/releases/v1.1.3.md
96
+ - docs/releases/v1.1.4.md
96
97
  - docs/upgrading-to-1.1.0.md
97
98
  - docs/upgrading.md
98
99
  - lib/achilles.rb