Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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