Skip to content

Commit 7e92502

Browse files
justin808claude
andcommitted
Revert to standard methods and target ES2022 for Stimulus compatibility
The arrow function approach didn't work because class fields are transformed differently by SWC, preventing Stimulus from discovering controller methods. Changes: - Reverted arrow functions back to standard class methods - Changed SWC target from es2015 to es2022 to minimize class transformations - Added optimizer config to preserve class structure - Kept keepClassNames: true and loose: false for spec-compliant transforms ES2022 has native support for modern class features, so SWC should apply minimal transformations that preserve Stimulus's ability to discover and bind controller methods. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent dd01474 commit 7e92502

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

client/app/controllers/comments_controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ marked.use(mangle());
1010
export default class CommentsController extends Controller {
1111
static targets = ['commentList', 'commentAuthor', 'commentText', 'commentRefresh', 'alertDiv', 'errorList'];
1212

13-
resetText = () => {
13+
resetText() {
1414
const inputAuthor = this.commentAuthorTarget;
1515
const inputText = this.commentTextTarget;
1616
const alertDiv = this.alertDivTarget;
@@ -41,12 +41,12 @@ export default class CommentsController extends Controller {
4141
}
4242
}
4343

44-
refreshCommentList = () => {
44+
refreshCommentList() {
4545
const refreshBtn = this.commentRefreshTarget;
4646
refreshBtn.click();
4747
}
4848

49-
connect = () => {
49+
connect() {
5050
console.log('connected to Stimulus comments_controller');
5151

5252
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';

config/swc.config.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,24 @@ module.exports = {
1313
transform: {
1414
react: {
1515
runtime: "automatic"
16+
},
17+
// Disable optimizer to preserve class structure for Stimulus
18+
optimizer: {
19+
globals: {
20+
vars: {}
21+
}
1622
}
1723
},
18-
// Critical for Stimulus: preserve class names and use spec-compliant transforms
24+
// Critical for Stimulus: preserve class names and method bindings
1925
keepClassNames: true,
2026
// Use spec-compliant class transforms (not loose mode)
2127
loose: false,
22-
// Don't use external helpers to avoid any potential binding issues
28+
// Don't use external helpers
2329
externalHelpers: false,
24-
target: "es2015"
30+
// Target ES2022 to avoid transforming class features
31+
target: "es2022"
2532
},
26-
// Preserve original semantics for class fields/methods
33+
// Preserve ES6 module semantics
2734
module: {
2835
type: "es6"
2936
}

0 commit comments

Comments
 (0)