Skip to content

Commit 2d51b5f

Browse files
alan-agius4AndrewKushnir
authored andcommitted
Revert "fix(platform-server): insert transfer state script before other script tags (#48868)" (#49112)
This reverts commit 2fc5b70 as this change is no longer needed since `type=module` script are deferred by default. Which causes the transfer data to be queried after the browser has finished parsing the DOM. PR Close #49112
1 parent f12ba1c commit 2d51b5f

File tree

2 files changed

+5
-40
lines changed

2 files changed

+5
-40
lines changed

packages/platform-server/src/transfer_state.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ function serializeTransferStateFactory(doc: Document, appId: string, transferSto
3535
script.id = appId + '-state';
3636
script.setAttribute('type', 'application/json');
3737
script.textContent = escapeHtml(content);
38-
const existingScript = doc.body.querySelector('script');
39-
if (existingScript) {
40-
// Insert the state script before any script so that the the script is available
41-
// before Angular is bootstrapped as otherwise this can causes the state not to be present.
42-
existingScript.before(script);
43-
} else {
44-
doc.body.appendChild(script);
45-
}
38+
39+
// It is intentional that we add the script at the very bottom. Angular CLI script tags for
40+
// bundles are always `type="module"`. These are deferred by default and cause the transfer
41+
// transfer data to be queried only after the browser has finished parsing the DOM.
42+
doc.body.appendChild(script);
4643
};
4744
}
4845

packages/platform-server/test/transfer_state_spec.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,36 +83,4 @@ describe('transfer_state', () => {
8383
const output = await renderModule(TransferStoreModule, {document: '<app></app>'});
8484
expect(output).toBe(defaultExpectedOutput);
8585
});
86-
87-
it('adds transfer script tag before any existing script tags', async () => {
88-
const STATE_KEY = makeStateKey<number>('test');
89-
90-
@Component({selector: 'app', template: 'Works!'})
91-
class TransferComponent {
92-
constructor(private transferStore: TransferState) {
93-
this.transferStore.onSerialize(STATE_KEY, () => 10);
94-
}
95-
}
96-
97-
@NgModule({
98-
bootstrap: [TransferComponent],
99-
declarations: [TransferComponent],
100-
imports: [BrowserModule.withServerTransition({appId: 'transfer'}), ServerModule],
101-
})
102-
class TransferStoreModule {
103-
}
104-
105-
const output = await renderModule(TransferStoreModule, {
106-
document: '<app></app><script src="polyfills.js"></script><script src="main.js"></script>'
107-
});
108-
expect(output).toContain(
109-
'<body>' +
110-
'<app ng-version="0.0.0-PLACEHOLDER" ng-server-context="other">Works!</app>' +
111-
'<script id="transfer-state" type="application/json">' +
112-
'{&q;test&q;:10}' +
113-
'</script>' +
114-
'<script src="polyfills.js"></script>' +
115-
'<script src="main.js"></script>' +
116-
'</body>');
117-
});
11886
});

0 commit comments

Comments
 (0)