Skip to content

Conversation

Copy link

Copilot AI commented Oct 1, 2025

Overview

This PR refactors the Template class in packages/common/src/templates/template.ts to eliminate code duplication by extracting common view tab definitions into reusable constants.

Problem

The CLIENT_VIEWS and SERVER_VIEWS configurations contained duplicate view tab definitions:

  • codesandbox.browser appeared in both CLIENT_VIEWS and SERVER_VIEWS
  • codesandbox.console appeared in both CLIENT_VIEWS and SERVER_VIEWS
  • codesandbox.problems appeared in both CLIENT_VIEWS and SERVER_VIEWS

This duplication violated the DRY (Don't Repeat Yourself) principle and made the code harder to maintain, as any changes to these view definitions would need to be made in multiple places.

Solution

Extracted the three duplicate view tab definitions into typed constants:

const BROWSER_VIEW: ViewTab = { id: 'codesandbox.browser' };
const CONSOLE_VIEW: ViewTab = { id: 'codesandbox.console' };
const PROBLEMS_VIEW: ViewTab = { id: 'codesandbox.problems' };

Both CLIENT_VIEWS and SERVER_VIEWS now reference these constants instead of creating new object literals, ensuring a single source of truth for these view definitions.

Benefits

  • Maintainability: Changes to common view properties only need to be made once
  • Readability: Descriptive constant names make the code more self-documenting
  • Type Safety: Constants maintain full TypeScript type checking via the ViewTab type
  • Backward Compatibility: The output structure remains functionally identical (verified via equivalence testing)

Testing

Verified that the refactored code produces identical JSON output for both CLIENT_VIEWS and SERVER_VIEWS configurations, ensuring no behavioral changes.

Original prompt

two great minds think alike. colaborate with your teamate Snyk. Master problem solving with class.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@snyk-io
Copy link

snyk-io bot commented Oct 1, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

Co-authored-by: ivan09069 <202161141+ivan09069@users.noreply.github.com>
Copilot AI changed the title [WIP] two great minds think alike. colaborate with your teamate Snyk. Master problem solving with class. Refactor template views to follow DRY principle by extracting duplicate view tab definitions Oct 1, 2025
Copilot AI requested a review from ivan09069 October 1, 2025 01:58
Copilot finished work on behalf of ivan09069 October 1, 2025 01:58
@ivan09069 ivan09069 marked this pull request as ready for review October 1, 2025 18:42
@ivan09069 ivan09069 merged commit bd0c2f0 into main Oct 1, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants