Refactor template views to follow DRY principle by extracting duplicate view tab definitions #43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR refactors the
Templateclass inpackages/common/src/templates/template.tsto eliminate code duplication by extracting common view tab definitions into reusable constants.Problem
The
CLIENT_VIEWSandSERVER_VIEWSconfigurations contained duplicate view tab definitions:codesandbox.browserappeared in both CLIENT_VIEWS and SERVER_VIEWScodesandbox.consoleappeared in both CLIENT_VIEWS and SERVER_VIEWScodesandbox.problemsappeared in both CLIENT_VIEWS and SERVER_VIEWSThis 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:
Both
CLIENT_VIEWSandSERVER_VIEWSnow reference these constants instead of creating new object literals, ensuring a single source of truth for these view definitions.Benefits
ViewTabtypeTesting
Verified that the refactored code produces identical JSON output for both CLIENT_VIEWS and SERVER_VIEWS configurations, ensuring no behavioral changes.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.