fix(alpine): wrap all Alpine.data() callbacks in arrow functions for proper component initialization
- Wrap all Alpine.data() object literals in arrow functions (() => ({}))
- This fixes "n.bind is not a function" errors when Alpine initializes components
- Alpine.data() requires a factory function, not a plain object
- Ensures each component instance gets its own closure and proper this binding
Fixed 24 TypeScript files:
- admin.ts, analytics.ts, api.ts, api-explorer-docs.ts
- bookshelf.ts, collection-rules.ts, collections.ts, conflicts.ts
- device-management.ts, docs.ts, header.ts, index.ts
- library.ts, linking.ts, login.ts, password_validation.ts
- profile-modal.ts, profile.ts, queue.ts, register.ts
- search.ts, theme.ts, toast-error.ts, toast.ts, unlinked_books.ts
Before: Alpine.data("name", { method1, method2 })
After: Alpine.data("name", () => ({ method1, method2 }))
This is a critical fix for Alpine.js v3+ where components must be
registered as factory functions to ensure proper reactivity and
prevent binding errors during initialization.
This commit is contained in:
@@ -251,7 +251,8 @@ async function testRule(): Promise<void> {
|
||||
'<p style="color: var(--text-secondary); font-size: 0.875rem;">Found ' +
|
||||
result.matches.length +
|
||||
" matching books:</p>";
|
||||
html += '<div style="display: flex; flex-direction: column; gap: 0.5rem;">';
|
||||
html +=
|
||||
'<div style="display: flex; flex-direction: column; gap: 0.5rem;">';
|
||||
|
||||
result.matches.slice(0, 20).forEach((book: TestRuleMatch) => {
|
||||
html +=
|
||||
@@ -408,7 +409,7 @@ export {
|
||||
toggleRule,
|
||||
};
|
||||
|
||||
Alpine.store("collectionRules", {
|
||||
Alpine.data("collectionRules", () => ({
|
||||
backToCollection,
|
||||
clearForm,
|
||||
deleteRule,
|
||||
@@ -422,4 +423,4 @@ Alpine.store("collectionRules", {
|
||||
setupEventDelegation,
|
||||
testRule,
|
||||
toggleRule,
|
||||
});
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user