( doc: Document, appId: string, )
| 148 | } |
| 149 | |
| 150 | export function retrieveTransferredState( |
| 151 | doc: Document, |
| 152 | appId: string, |
| 153 | ): Record<string, unknown | undefined> { |
| 154 | // Locate the script tag with the JSON data transferred from the server. |
| 155 | // The id of the script tag is set to the Angular appId + 'state'. |
| 156 | const script = doc.getElementById(appId + '-state'); |
| 157 | if (script?.tagName === 'SCRIPT' && script.textContent) { |
| 158 | try { |
| 159 | // Avoid using any here as it triggers lint errors in google3 (any is not allowed). |
| 160 | // Decoding of `<` is done of the box by browsers and node.js, same behaviour as G3 |
| 161 | // script_builders. |
| 162 | return JSON.parse(script.textContent) as {}; |
| 163 | } catch (e) { |
| 164 | console.warn('Exception while restoring TransferState for app ' + appId, e); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | return {}; |
| 169 | } |
no test coverage detected
searching dependent graphs…