( doc: Document, appId: string, )
| 158 | } |
| 159 | |
| 160 | export function retrieveTransferredState( |
| 161 | doc: Document, |
| 162 | appId: string, |
| 163 | ): Record<string, unknown | undefined> { |
| 164 | // Locate the script tag with the JSON data transferred from the server. |
| 165 | // The id of the script tag is set to the Angular appId + 'state'. |
| 166 | const script = doc.getElementById(appId + '-state'); |
| 167 | if (script?.tagName === 'SCRIPT' && script.textContent) { |
| 168 | try { |
| 169 | // Avoid using any here as it triggers lint errors in google3 (any is not allowed). |
| 170 | // Decoding of `<` is done of the box by browsers and node.js, same behaviour as G3 |
| 171 | // script_builders. |
| 172 | return Object.assign( |
| 173 | createDictionary<unknown | undefined>(), |
| 174 | JSON.parse(script.textContent) as {}, |
| 175 | ); |
| 176 | } catch (e) { |
| 177 | console.warn('Exception while restoring TransferState for app ' + appId, e); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | return createDictionary(); |
| 182 | } |
no test coverage detected