-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MWPW-168334 Load georoutingv2.json and georoutingv2.js in parallel #3720
base: stage
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,6 +271,7 @@ export default async function loadGeoRouting( | |
getMetadataFunc, | ||
loadBlockFunc, | ||
loadStyleFunc, | ||
v2jsonPromise, | ||
) { | ||
if (getGeoroutingOverride()) return; | ||
config = conf; | ||
|
@@ -279,25 +280,22 @@ export default async function loadGeoRouting( | |
loadBlock = loadBlockFunc; | ||
loadStyle = loadStyleFunc; | ||
|
||
const urls = [ | ||
`${config.contentRoot ?? ''}/georoutingv2.json`, | ||
`${config.contentRoot ?? ''}/georouting.json`, | ||
`${getFederatedContentRoot()}/federal/georouting/georoutingv2.json`, | ||
]; | ||
let resp; | ||
for (const url of urls) { | ||
resp = await fetch(url); | ||
if (resp.ok) { | ||
if (url.includes('georouting.json')) { | ||
const json = await resp.json(); | ||
// eslint-disable-next-line import/no-cycle | ||
const { default: loadGeoRoutingOld } = await import('../georouting/georouting.js'); | ||
loadGeoRoutingOld(config, createTag, getMetadata, json); | ||
} | ||
break; | ||
} | ||
} | ||
const json = await resp.json(); | ||
const loadOldGeorouting = async (json) => { | ||
const { default: loadGeoRoutingOld } = await import('../georouting/georouting.js'); | ||
await loadGeoRoutingOld(config, createTag, getMetadata, json); | ||
return 'use-old-georouting'; | ||
}; | ||
const oldGeorouting = () => fetch(`${config.contentRoot ?? ''}/georouting.json`) | ||
.then((r) => r.json()) | ||
.then(loadOldGeorouting) | ||
.catch(() => null); | ||
const federatedJSON = () => fetch(`${getFederatedContentRoot()}/federal/georouting/georoutingv2.json`) | ||
.then((r) => r.json()) | ||
.catch(() => null); | ||
|
||
const json = (await v2jsonPromise) ?? (await oldGeorouting()) ?? (await federatedJSON()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're kind of cramming multiple asynchronous operations and fallback logic into a single expression here. I'd separate this out for readability. |
||
if (json === 'use-old-georouting') return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would really recommend avoiding things like magic strings - https://softwareengineering.stackexchange.com/questions/365339/what-is-wrong-with-magic-strings |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on my upper comments, I'd maybe even just edit to something simpler like so (this is untested btw). Your call on how you want to do it though:
|
||
const { locale } = config; | ||
|
||
const urlLocale = locale.prefix.replace('/', ''); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1250,8 +1250,11 @@ async function loadPostLCP(config) { | |
|
||
const georouting = getMetadata('georouting') || config.geoRouting; | ||
if (georouting === 'on') { | ||
const jsonPromise = fetch(`${config.contentRoot ?? ''}/georoutingv2.json`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to keep this even leaner , you could probably only call the fetch right? (without any .then or .catch handling) |
||
.then((r) => r.json()) | ||
.catch(() => null); | ||
const { default: loadGeoRouting } = await import('../features/georoutingv2/georoutingv2.js'); | ||
await loadGeoRouting(config, createTag, getMetadata, loadBlock, loadStyle); | ||
await loadGeoRouting(config, createTag, getMetadata, loadBlock, loadStyle, jsonPromise); | ||
} | ||
const header = document.querySelector('header'); | ||
if (header) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you give this the default value of a promise fetch to the georoutingV2.json file?