Skip to content

🟠 10. Race Condition with Form Initialization #163

@juancolchete

Description

@juancolchete

10. Race Condition with Form Initialization

Location: templates/add_area.html:167-170

const issueId = GetURLParameter("issue-id")
if(issueId){
    fillFieldsPassingIssue(issueId)  // ❌ Async but not awaited
}

// Later... this might run before fillFieldsPassingIssue completes
if (templateArea && templateArea.tags) {
    typeSelect.value = templateArea.tags.type;
    updateFields();
    // ...
}

Problem: May try to set values before form fields exist.

Fix: Ensure proper sequencing in suggested error handling above (Priority #5).

πŸ’‘ Architectural Suggestion: Use Server-Side Validation

Current Approach Issues

The commits mention "feat: validate description length" and "feat: validate lightning tips length" but these are client-side filters, not validation:

// This is filtering, not validation - can be bypassed
if(prefilledCommunityData?.lightningTips.length > 10){
    newRow = createTagRow('tips:lightning_address', prefilledCommunityData.lightningTips, false, false);
    tagsTable.appendChild(newRow);
}

Better Approach: Enhance Existing Server-Side Validation

The codebase already has a robust validation framework (app.py:1016-1144) that should be leveraged. Instead of client-side checks, enhance the server-side validation:

Current structure:

AREA_TYPE_REQUIREMENTS = {
    'community': {
        'description': {
            'required': False,
            'type': 'text'  # ← Only has required and type
        }
    }
}

Suggested enhancement:

AREA_TYPE_REQUIREMENTS = {
    'community': {
        'description': {
            'required': False,
            'type': 'text',
            'min_length': 10,      # ← Add constraints
            'max_length': 500
        },
        'tips:lightning_address': {
            'required': False,
            'type': 'text',
            'min_length': 10,
            'pattern': r'^[\w\.\-]+@[\w\.\-]+\.[a-zA-Z]{2,}$'  # Lightning address format
        },
        'contact:nostr': {
            'required': False,
            'type': 'text',
            'pattern': r'^npub1[a-z0-9]{58}$'  # Nostr npub format
        },
        'url_alias': {
            'required': True,
            'type': 'text',
            'pattern': r'^[a-z0-9\-]+$',  # Slug format
            'min_length': 2,
            'max_length': 100
        }
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions