Skip to content

[Playground][Frontend] : Persist editor state and SDK selection in localStorage #37211

@Kalpana-chavhan

Description

@Kalpana-chavhan

Description

Currently, the Apache Beam Playground loses all user progress (editor content and SDK selection) upon a page refresh. This creates significant friction for users who are experimenting with code or accidentally trigger a browser reload.

Proposed Change

I propose implementing a persistence layer using the browser's localStorage API to cache the following:

  1. Editor Content: The current string in the Monaco editor.
  2. Selected SDK: The active language (Java, Python, Go, SCIO).
  3. User-defined vs Example: Whether the user is viewing a standard example or their own custom code.

Technical Strategy

  1. State Hydration: Load state from localStorage during store initialization to prevent UI flickering.
  2. Debounced Writes: Implement a 500ms-1000ms debounce for localStorage.setItem calls to ensure editor performance remains high.
  3. Safety: Wrap JSON parsing in try/catch blocks to prevent app crashes if local data is corrupted.

Impact

  • DX Improvement: Users can return to their work even after closing the tab.
  • Zero Backend Impact: This is a localized frontend change that requires no API modifications.
  • Testability: The persistence logic can be verified via unit tests (Jest/Vitest).

I am willing to contribute

I have analyzed the playground/frontend directory and have a draft implementation ready using TypeScript.

Metadata

Metadata

Assignees

No one assigned

    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