Templates: Fix "Discard changes?" dialog after creating template with master template (fixes #20262) #20749
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.
Prerequisites
Fixes: #20262
Description
This PR fixes a bug where the "Discard changes?" dialog appears after creating and saving a template with a master template, even though no changes were made.
Root Cause
When a template is created with a master template and saved:
/create/...to/edit/{id}load()method sets both persisted and current data from the serversetMasterTemplate(unique, false)is called to update the UI_data.updateCurrent()call was executing even whenupdateLayoutBlock=false, causing the current data to diverge from persisted dataThe Fix
Moves the
_data.updateCurrent({ masterTemplate: unique ? { unique } : null })call inside theif (updateLayoutBlock)block in thesetMasterTemplate()method.This completes the fix started in PR #20529, which added the
updateLayoutBlockparameter to prevent overwriting layout settings from disk, but inadvertently left the data model update outside the conditional.Before:
After:
Why This Works
updateLayoutBlock=false(during load): We only update the#masterTemplateobservable for UI display, without modifying the data model or contentupdateLayoutBlock=true(during user actions): We update both the layout block in the Razor content AND the data model, properly marking the workspace as having changesTesting
Test 1: Creating a Template with Master Template (Issue #20262)
Test 2: Creating a Sub-Template Under a Parent
Layout = "ParentTemplate.cshtml";Test 3: Changing Master Template via UI Picker
Layout = "NewMaster.cshtml";)Test 4: Removing Master Template via UI
Layout = null;Test 5: Preserving Layout from Disk (PR #20529 regression check)
Layout = "LayoutBase.cshtml";Layout = "LayoutBase.cshtml";(not overwritten toLayout = null;)