Skip to content

Theme handling functions are duplicated in article.hbs template #266

@pekkah

Description

@pekkah

Description

The generated ui-bundle/article.hbs template contains duplicated theme handling functions in two different script blocks, which increases maintenance overhead.

Current Behavior

The following functions appear twice in the generated template:

  • getStoredTheme
  • setStoredTheme
  • getPreferredTheme
  • setTheme

First occurrence: In the <head> section (necessary to prevent FOUC - flash of unstyled content)
Second occurrence: In the body script for handling user interactions

Expected Behavior

The theme handling functions should be defined once and reused to avoid duplication.

Suggested Solution

Consider refactoring the template to expose these functions on a global object from the first script, which the second script can then consume. For example:

// In <head> script
window.themeUtils = {
  getStoredTheme,
  setStoredTheme,
  getPreferredTheme,
  setTheme
};

// In body script
const { getStoredTheme, setStoredTheme, getPreferredTheme, setTheme } = window.themeUtils;

Impact

This duplication doesn't affect functionality but makes the template harder to maintain, as any changes to these functions need to be made in two places.

Found In

This issue was discovered during a code review by Gemini Code Assist on chibi-ui-2 PR #88.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions