Skip to content

Commit 0f72ca4

Browse files
mhartingtonclydin
authored andcommitted
fix(@angular-devkit/build-angular): ignore hidden inputs with hmr
Closes #19385 Don't query for hidden inputs when using HMR
1 parent 9d82269 commit 0f72ca4

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/angular_devkit/build_angular/src/dev-server/hmr_spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ describe('Dev Server Builder HMR', () => {
5656
'src/app/app.component.html': `
5757
<p>{{title}}</p>
5858
59-
<input type="text">
60-
59+
<input class="visible" type="text">
60+
<input type="hidden">
6161
<select>
6262
<option>one</option>
6363
<option>two</option>
@@ -165,7 +165,7 @@ describe('Dev Server Builder HMR', () => {
165165
await page.goto(url);
166166
expect(logs).toContain('[HMR] Waiting for update signal from WDS...');
167167
await page.evaluate(() => {
168-
document.querySelector('input').value = 'input value';
168+
document.querySelector('input.visible').value = 'input value';
169169
document.querySelector('select').value = 'two';
170170
});
171171

@@ -177,7 +177,7 @@ describe('Dev Server Builder HMR', () => {
177177
expect(logs).toContain('[NG HMR] Restoring input/textarea values.');
178178
expect(logs).toContain('[NG HMR] Restoring selected options.');
179179

180-
const inputValue = await page.evaluate(() => document.querySelector('input').value);
180+
const inputValue = await page.evaluate(() => document.querySelector('input.visible').value);
181181
expect(inputValue).toBe('input value');
182182

183183
const selectValue = await page.evaluate(() => document.querySelector('select').value);

packages/angular_devkit/build_angular/src/webpack/plugins/hmr/hmr-accept.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export default function (mod: any): void {
5252
return;
5353
}
5454

55-
const oldInputs = document.querySelectorAll('input, textarea');
55+
// Inputs that are hidden should be ignored
56+
const oldInputs = document.querySelectorAll('input:not([type="hidden"]), textarea');
5657
const oldOptions = document.querySelectorAll('option');
5758

5859
// Create new application
@@ -160,8 +161,8 @@ function dispatchEvents(element: any): void {
160161
}
161162

162163
function restoreFormValues(oldInputs: any[], oldOptions: any[]): void {
163-
// Restore input
164-
const newInputs = document.querySelectorAll('input, textarea');
164+
// Restore input that are not hidden
165+
const newInputs = document.querySelectorAll('input:not([type="hidden"]), textarea');
165166
if (newInputs.length && newInputs.length === oldInputs.length) {
166167
console.log('[NG HMR] Restoring input/textarea values.');
167168
for (let index = 0; index < newInputs.length; index++) {

0 commit comments

Comments
 (0)