LearnNewsExamplesServices
Frontmatter
id8064
titleOptimize LivePreview Renderer Loading & Lifecycle
stateClosed
labels
enhancementairefactoringarchitecture
assigneestobiu
createdAtDec 9, 2025, 2:16 AM
updatedAtDec 9, 2025, 2:18 AM
githubUrlhttps://github.com/neomjs/neo/issues/8064
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtDec 9, 2025, 2:17 AM

Optimize LivePreview Renderer Loading & Lifecycle

Closed v11.17.0 enhancementairefactoringarchitecture
tobiu
tobiu commented on Dec 9, 2025, 2:16 AM

Optimize the renderer loading mechanism in Neo.code.LivePreview to prevent redundant module fetching and ensure smoother initialization.

Changes:

  1. Renderer Caching: Implement a renderers object to cache instantiated renderers.
  2. loadRenderer Method: Create a dedicated method to handle dynamic importing and caching.
  3. initAsync Integration: Use initAsync to await the initial renderer load, ensuring isReady state reflects renderer availability.
  4. Optimized afterSetLanguage: Update to only trigger loadRenderer on runtime changes (when oldValue exists).
  5. Execution Guard: Update afterSetRenderer to only trigger doRunSource if this.value is truthy, handling edge cases of simultaneous config application.
  6. Static Languages: Add static languages = ['markdown', 'neomjs'].
  7. beforeSetLanguage: Implement validation against the static languages array.

Goal: Improve performance and robustness of the LivePreview component when switching languages and initializing.

tobiu added the enhancement label on Dec 9, 2025, 2:16 AM
tobiu added the ai label on Dec 9, 2025, 2:16 AM
tobiu added the refactoring label on Dec 9, 2025, 2:16 AM
tobiu added the architecture label on Dec 9, 2025, 2:16 AM
tobiu assigned to @tobiu on Dec 9, 2025, 2:16 AM
tobiu referenced in commit db5ba73 - "Optimize LivePreview Renderer Loading & Lifecycle #8064" on Dec 9, 2025, 2:17 AM
tobiu closed this issue on Dec 9, 2025, 2:17 AM
tobiu
tobiu Dec 9, 2025, 2:18 AM

Input from Gemini:

✦ Refactoring complete.

Changes:

  1. Optimization: Implemented renderers cache in LivePreview.mjs to avoid redundant imports.
  2. loadRenderer: Added method for efficient dynamic loading and caching.
  3. Initialization: Updated initAsync to await initial renderer load.
  4. Lifecycle: Updated afterSetLanguage to handle runtime changes only.
  5. Robustness: Added && this.value check in afterSetRenderer to prevent execution on empty values.
  6. Validation: Added static languages array and beforeSetLanguage validation method.

Verified code changes.