achilles 1.1.1 → 1.1.3

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: d860cd0be6faa8af39117c4dc6feadb2445f48ccfd687963a3a8eeddbe1c3b95
4
- data.tar.gz: '09cdfabdfa0895b1a3c7a92726baf49cb234a9a716b8a1e3a65c7eb6e578904e'
3
+ metadata.gz: ffeb9aa323be59b9a1f276b8ceb3b881747733d6e5b10ceee31149df2b49d3e8
4
+ data.tar.gz: 9e0e0112177262df5c1cd7aaa5d76774d7e0b85b0b483c7d083a65d006f277d3
5
5
  SHA512:
6
- metadata.gz: 7899f56529ad2a867a289b546241023e235a1d848d3a22ceb1a396fb92a515c9edeb3b50decdec7d37e952f9c5fc524326c8d1fc3456e78f5e1c7db5be53c10d
7
- data.tar.gz: 7d43d1c196f608be65a27d42840cdd0a3f3bac7bb86870dec876b89bdbfdf63408465dabd265986322638300ab0d8287c3a747e2b2830ccc3c824bf74217318e
6
+ metadata.gz: f608ad668694d5067147da2087e07bc2ebeeb66a936cab3b267b8ebc7aaeaa9241f22f69997c7a5c9fd04fe5a0d58662b0c533afd8e6de70ec56cbbc6f9be911
7
+ data.tar.gz: 6bf2ecabb1506a16c888e2d2d3fb28d9d7a2ad43af0d2fa72b558e1f00f13ac08c1e1a0528206163a4996b6e094bfa6f2888e26f4e697fcac631c2c42302607f
data/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to Achilles will be documented in this file.
4
4
 
5
+ ## 1.1.3
6
+
7
+ ### Fixed
8
+
9
+ - Resolve component class names and IDs only among registered entries.
10
+
11
+ ## 1.1.2
12
+
13
+ ### Fixed
14
+
15
+ - Fixed Turbo Frame rendering so registered components in the outgoing frame are
16
+ torn down and deregistered immediately before Turbo invokes the frame renderer.
17
+
5
18
  ## 1.1.1
6
19
 
7
20
  ### Fixed
data/README.md CHANGED
@@ -8,9 +8,9 @@ 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
- Current applications should use Achilles `1.1.1`. If you are upgrading an
12
- existing app, start with the [1.1.0 upgrade guide](docs/upgrading-to-1.1.0.md)
13
- and then read the [1.1.1 release note](docs/releases/v1.1.1.md).
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).
14
14
 
15
15
  ## Why Achilles?
16
16
 
@@ -185,6 +185,9 @@ The dummy Rails app includes a working counter component. See
185
185
 
186
186
  - `setup()` runs after `turbo:load` and after new matching DOM nodes are inserted.
187
187
  - `teardown()` runs before Turbo renders a new page.
188
+ - Before Turbo renders replacement content in a frame, Achilles tears down and
189
+ deregisters registered components in the outgoing frame from children to
190
+ parents.
188
191
  - `setup()` and `teardown()` are called once per registered component instance.
189
192
  - Parent components are set up before their children.
190
193
  - Child components are torn down before their parents.
@@ -276,8 +279,8 @@ If no timezone is present, Achilles falls back to `Etc/UTC`.
276
279
 
277
280
  Applications upgrading to `1.1.0` should read the
278
281
  [1.1.0 upgrade guide](docs/upgrading-to-1.1.0.md). The complete upgrade index
279
- lives in [docs/upgrading.md](docs/upgrading.md), and the GitHub release draft is
280
- available at [docs/releases/v1.1.1.md](docs/releases/v1.1.1.md).
282
+ lives in [docs/upgrading.md](docs/upgrading.md), and the current release note is
283
+ available at [docs/releases/v1.1.3.md](docs/releases/v1.1.3.md).
281
284
 
282
285
  ## Upgrading From 0.1.3
283
286
 
@@ -4,6 +4,7 @@ class Turbo {
4
4
  _teardownCallback;
5
5
  _setupHandler;
6
6
  _teardownHandler;
7
+ _frameRenderHandler;
7
8
  _started = false;
8
9
 
9
10
  constructor(application, setupCallback, teardownCallback) {
@@ -27,8 +28,24 @@ class Turbo {
27
28
  this._teardownCallback();
28
29
  };
29
30
 
31
+ this._frameRenderHandler = (event) => {
32
+ const frame = event.target;
33
+ const originalRender = event.detail?.render;
34
+
35
+ if (!frame || typeof originalRender !== "function") {
36
+ return;
37
+ }
38
+
39
+ const componentRegistry = this._application.componentRegistry;
40
+ event.detail.render = function(...args) {
41
+ componentRegistry.teardownAndDeregisterWithin(frame);
42
+ return Reflect.apply(originalRender, this, args);
43
+ };
44
+ };
45
+
30
46
  document.addEventListener("turbo:load", this._setupHandler);
31
47
  document.addEventListener("turbo:before-render", this._teardownHandler);
48
+ document.addEventListener("turbo:before-frame-render", this._frameRenderHandler);
32
49
  this._started = true;
33
50
  }
34
51
 
@@ -39,8 +56,10 @@ class Turbo {
39
56
 
40
57
  document.removeEventListener("turbo:load", this._setupHandler);
41
58
  document.removeEventListener("turbo:before-render", this._teardownHandler);
59
+ document.removeEventListener("turbo:before-frame-render", this._frameRenderHandler);
42
60
  this._setupHandler = null;
43
61
  this._teardownHandler = null;
62
+ this._frameRenderHandler = null;
44
63
  this._started = false;
45
64
  }
46
65
  }
@@ -1,6 +1,6 @@
1
1
  // Single Responsibility: Contains the list of all view components so it can be instantiated
2
2
  class ComponentsClassMapper {
3
- _componentsClassMapper = {};
3
+ _componentsClassMapper = Object.create(null);
4
4
 
5
5
  addComponentClass(key, klass) {
6
6
  this._componentsClassMapper[key] = klass;
@@ -2,7 +2,7 @@ import { AppConstants } from "achilles/application/app_constants";
2
2
 
3
3
  // Contains all the registered components in a page at the current moment
4
4
  class ComponentsRegistry {
5
- _registeredComponents = {};
5
+ _registeredComponents = Object.create(null);
6
6
  strictLifecycleErrors = false;
7
7
 
8
8
  matchingElementsForId(id) {
@@ -130,6 +130,39 @@ class ComponentsRegistry {
130
130
  this.deregisterComponent(id);
131
131
  }
132
132
 
133
+ teardownAndDeregisterWithin(rootElement) {
134
+ if(!rootElement || typeof rootElement.contains !== 'function')
135
+ return;
136
+
137
+ Object.values(this._registeredComponents)
138
+ .filter((component) => {
139
+ if(component.id === AppConstants.PageComponentId)
140
+ return false;
141
+
142
+ let element = this.elementForId(component.id);
143
+ return element && rootElement.contains(element);
144
+ })
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);
151
+ });
152
+ }
153
+
154
+ elementDepth(id) {
155
+ let depth = 0;
156
+ let element = this.elementForId(id);
157
+
158
+ while(element?.parentElement) {
159
+ depth += 1;
160
+ element = element.parentElement;
161
+ }
162
+
163
+ return depth;
164
+ }
165
+
133
166
  elementNotFound(id) {
134
167
  console.error('Cannot find element while setup, so teardown & deregister. id: ' + id);
135
168
  this.teardownAndDeregister(id);
@@ -0,0 +1,58 @@
1
+ # Achilles 1.1.2
2
+
3
+ Achilles `1.1.2` is a patch release for Rails + Turbo applications using Turbo
4
+ Frames. It fixes late component cleanup when Turbo replaces frame content.
5
+
6
+ ## Who Should Upgrade
7
+
8
+ Upgrade from `1.1.0` or `1.1.1` if your application registers
9
+ Achilles-managed components inside a Turbo Frame or on the frame root itself.
10
+
11
+ There are no new application setup requirements in this patch release. Apps
12
+ upgrading from versions before `1.1.0` should still read the
13
+ [1.1.0 upgrade guide](../upgrading-to-1.1.0.md).
14
+
15
+ ## Fixed
16
+
17
+ - Registered components in an outgoing Turbo Frame are now torn down and
18
+ deregistered immediately before Turbo invokes the frame renderer.
19
+ - Cleanup runs from children to parents and includes the frame root when it is
20
+ registered as a component.
21
+ - The original Turbo renderer keeps its receiver, arguments, return value, and
22
+ error behavior.
23
+ - Incoming components continue to register through the existing DOM observer,
24
+ while ordinary non-Turbo removal behavior remains unchanged.
25
+ - Starting and stopping an Achilles application manages the frame-render
26
+ listener without creating duplicates.
27
+
28
+ ## Compatibility
29
+
30
+ This backward-compatible `1.1.x` patch intentionally moves frame-contained
31
+ teardown earlier, while the outgoing component elements are still present,
32
+ instead of relying on missing-element recovery after replacement.
33
+
34
+ Achilles continues to require Turbo Rails `2.0.11` or newer. This release does
35
+ not add dependencies or require an application migration.
36
+
37
+ ## Verification
38
+
39
+ This release was verified with:
40
+
41
+ ```bash
42
+ bin/rails test
43
+ node --test test/javascript/*_test.mjs
44
+ for file in $(rg --files app/javascript/achilles test/dummy/app/javascript test/javascript | rg "\.(js|mjs)$"); do node --input-type=module --check < "$file" || exit 1; done
45
+ bin/rails test:system
46
+ RAILS_ENV=test bin/rails app:assets:precompile
47
+ gem build achilles.gemspec
48
+ ```
49
+
50
+ The system suite covers a native Turbo Frame replacement with a registered
51
+ frame root, nested outgoing components, incoming component registration and
52
+ interaction, and browser-console error checks.
53
+
54
+ ## Links
55
+
56
+ - [Changelog](../../CHANGELOG.md)
57
+ - [Upgrade index](../upgrading.md)
58
+ - [1.1.0 upgrade guide](../upgrading-to-1.1.0.md)
@@ -0,0 +1,14 @@
1
+ # Achilles 1.1.3
2
+
3
+ Achilles now looks up component class names and IDs only among registered
4
+ entries. This fixes lookups when a class name or ID matches a built-in
5
+ JavaScript object property.
6
+
7
+ ## Upgrading
8
+
9
+ Update the Achilles gem to `1.1.3` and keep your existing component markup and
10
+ registration code. If you are upgrading from a version earlier than `1.1.0`,
11
+ start with the [1.1.0 upgrade guide](../upgrading-to-1.1.0.md).
12
+
13
+ - [Changelog](../../CHANGELOG.md)
14
+ - [Upgrade index](../upgrading.md)
data/docs/upgrading.md CHANGED
@@ -12,6 +12,8 @@ setup, component markup, lifecycle behavior, or public APIs.
12
12
 
13
13
  ## Release Notes
14
14
 
15
+ - [Achilles 1.1.3](releases/v1.1.3.md)
16
+ - [Achilles 1.1.2](releases/v1.1.2.md)
15
17
  - [Achilles 1.1.1](releases/v1.1.1.md)
16
18
  - [Achilles 1.1.0](releases/v1.1.0.md)
17
19
 
@@ -1,3 +1,3 @@
1
1
  module Achilles
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.3"
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.1
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jey Geethan
@@ -87,14 +87,14 @@ files:
87
87
  - app/views/layouts/achilles/application.html.erb
88
88
  - config/importmap.rb
89
89
  - config/routes.rb
90
- - docs/core-js-gaps.md
91
90
  - docs/migrating-from-0.1.3-to-v1.md
92
91
  - docs/release-checklist.md
93
92
  - docs/releases/v1.1.0.md
94
93
  - docs/releases/v1.1.1.md
94
+ - docs/releases/v1.1.2.md
95
+ - docs/releases/v1.1.3.md
95
96
  - docs/upgrading-to-1.1.0.md
96
97
  - docs/upgrading.md
97
- - docs/v1-roadmap.md
98
98
  - lib/achilles.rb
99
99
  - lib/achilles/engine.rb
100
100
  - lib/achilles/version.rb
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 4.0.11
123
+ rubygems_version: 3.6.9
124
124
  specification_version: 4
125
125
  summary: JavaScript component lifecycle for Rails and Turbo apps
126
126
  test_files: []
data/docs/core-js-gaps.md DELETED
@@ -1,26 +0,0 @@
1
- # Core JavaScript Gaps
2
-
3
- This is the current improvement backlog for Achilles core JavaScript. API
4
- reference docs should wait until the structure settles.
5
-
6
- ## Completed
7
-
8
- - Added an explicit `Application#start` and `Application#stop` lifecycle.
9
- - Made Turbo event listeners removable.
10
- - Validated that component roots have non-empty ids before registration.
11
- - Changed teardown order so child components tear down before parent components.
12
- - Deleted deregistered registry entries instead of leaving `null` tombstones.
13
- - Batched mutation observer setup work with a microtask debounce.
14
- - Replaced one-way lifecycle flags with a `mounted` state while keeping
15
- `setupExecuted` and `teardownExecuted` as compatibility aliases.
16
- - Added tests for missing ids, duplicate starts, listener cleanup,
17
- child-before-parent teardown, dynamic insertion batching, deregistration, and
18
- remounting a reused component instance.
19
- - Chose a DOM ancestry model for nested components under the single synthetic
20
- `Page` root.
21
- - Split JavaScript tests by parser, registry, application, Turbo hooks, and
22
- component base responsibility.
23
- - Added package/file-list regression coverage for the gemspec.
24
- - Added opt-in strict lifecycle error handling for tests and development.
25
-
26
- ## Remaining Priority Gaps
data/docs/v1-roadmap.md DELETED
@@ -1,68 +0,0 @@
1
- # Achilles v1 Roadmap
2
-
3
- This document tracks the work needed before publishing Achilles `1.0.0`.
4
- The goal is a stable open source release that is safe to evaluate in real Rails
5
- applications, even if it intentionally removes legacy behavior from the `0.x`
6
- line.
7
-
8
- ## Product Direction
9
-
10
- Achilles is a small JavaScript lifecycle layer for Rails + Turbo applications.
11
- It gives teams explicit component classes mapped to DOM nodes without requiring
12
- Stimulus controller conventions or a JavaScript build step.
13
-
14
- ## v1 Public API
15
-
16
- The v1 API should be small and documented:
17
-
18
- - `Application`
19
- - `ComponentBase`
20
- - `ComponentsClassMapper`
21
- - DOM discovery through `data-component-class`
22
- - component root lookup through `rootElement()`
23
- - `rootNode()` as an alias for `rootElement()`
24
- - CSS selector lookup through `rootElementSelector()`
25
- - lifecycle hooks: `setup()` and `teardown()`
26
- - Turbo integration through `turbo:load` and `turbo:before-render`
27
-
28
- ## Planned Breaking Changes
29
-
30
- - Make `rootElement()` return the component's DOM element.
31
- - Keep `rootNode()` as an alias for `rootElement()`.
32
- - Remove the jQuery return behavior from `rootElement()`.
33
- - Keep Achilles internals independent from jQuery.
34
- - Require every component root to have a unique `id`.
35
- - Treat setup and teardown as idempotent lifecycle operations managed by
36
- Achilles.
37
-
38
- ## Release Gates
39
-
40
- Do not publish `1.0.0` until these are true:
41
-
42
- - Rails test suite passes.
43
- - JavaScript lifecycle tests cover parser, registry, Turbo hooks, root lookup,
44
- setup idempotence, teardown idempotence, missing elements, and dynamic DOM
45
- insertion.
46
- - Dummy app asset precompile passes.
47
- - README includes install, usage, lifecycle, dynamic DOM, migration, and API
48
- reference sections.
49
- - `CHANGELOG.md` documents all breaking changes from `0.1.3`.
50
- - CI runs tests on supported Ruby and Rails versions.
51
- - At least one real application has tested the release candidate.
52
-
53
- ## Release Plan
54
-
55
- 1. Publish a compatibility release in the `0.x` line with dependency and
56
- lifecycle fixes.
57
- 2. Create a `v1.0.0.rc1` prerelease after the v1 API and tests are complete.
58
- 3. Test `v1.0.0.rc1` in existing applications.
59
- 4. Publish `1.0.0` only after the migration guide and real-app testing are done.
60
-
61
- Follow the [release checklist](release-checklist.md) when building and testing
62
- release candidates.
63
-
64
- ## Current Recommendation
65
-
66
- Do not push `v1.0.0` yet. The project is ready for a compatibility release, but
67
- `1.0.0` should wait for the final v1 API cleanup and real-application testing
68
- through a release candidate.