Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): ignore hidden inputs with hmr
Browse files Browse the repository at this point in the history
Closes #19385
Don't query for hidden inputs when using HMR

(cherry picked from commit 0f72ca4)
  • Loading branch information
mhartington authored and clydin committed Nov 16, 2020
1 parent 115a878 commit 467af26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ describe('Dev Server Builder HMR', () => {
'src/app/app.component.html': `
<p>{{title}}</p>
<input type="text">
<input class="visible" type="text">
<input type="hidden">
<select>
<option>one</option>
<option>two</option>
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('Dev Server Builder HMR', () => {
await page.goto(url);
expect(logs).toContain('[HMR] Waiting for update signal from WDS...');
await page.evaluate(() => {
document.querySelector('input').value = 'input value';
document.querySelector('input.visible').value = 'input value';
document.querySelector('select').value = 'two';
});

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

const inputValue = await page.evaluate(() => document.querySelector('input').value);
const inputValue = await page.evaluate(() => document.querySelector('input.visible').value);
expect(inputValue).toBe('input value');

const selectValue = await page.evaluate(() => document.querySelector('select').value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default function (mod: any): void {
return;
}

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

// Create new application
Expand Down Expand Up @@ -160,8 +161,8 @@ function dispatchEvents(element: any): void {
}

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

0 comments on commit 467af26

Please sign in to comment.