Skip to content
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

Check if hashUrlSearchParams has p[meta_page_view_id] #6710

Merged
merged 4 commits into from
Jan 21, 2025

Conversation

GHaberis
Copy link
Contributor

@GHaberis GHaberis commented Jan 20, 2025

What are you doing in this PR?

An alternate log to #6694, as the original log didn't report anything in ~5 days. I wondered whether hashUrlSearchParams contained a 'p[meta_page_view_id] key as we'd expect, we can check this using https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/has. If not log an expection in Sentry.

Copy link
Contributor

github-actions bot commented Jan 20, 2025

Size Change: +20 B (0%)

Total Size: 2.37 MB

ℹ️ View Unchanged
Filename Size Change
./public/compiled-assets/javascripts/[countryGroupId]/events/router.js 90.5 kB +20 B (+0.02%)
./public/compiled-assets/javascripts/[countryGroupId]/lazyRouter.js 93.2 kB 0 B
./public/compiled-assets/javascripts/[countryGroupId]/router.js 254 kB 0 B
./public/compiled-assets/javascripts/ausMomentMap.js 108 kB 0 B
./public/compiled-assets/javascripts/contributionsRedirectStyles.js 20 B 0 B
./public/compiled-assets/javascripts/digitalSubscriptionLandingPage.js 223 kB 0 B
./public/compiled-assets/javascripts/downForMaintenancePage.js 67.7 kB 0 B
./public/compiled-assets/javascripts/error404Page.js 67.6 kB 0 B
./public/compiled-assets/javascripts/error500Page.js 67.5 kB 0 B
./public/compiled-assets/javascripts/favicons.js 617 B 0 B
./public/compiled-assets/javascripts/paperSubscriptionCheckoutPage.js 164 kB 0 B
./public/compiled-assets/javascripts/paperSubscriptionLandingPage.js 87.9 kB 0 B
./public/compiled-assets/javascripts/payPalErrorPage.js 66.1 kB 0 B
./public/compiled-assets/javascripts/payPalErrorPageStyles.js 20 B 0 B
./public/compiled-assets/javascripts/promotionTerms.js 73.8 kB 0 B
./public/compiled-assets/javascripts/subscriptionsLandingPage.js 73.2 kB 0 B
./public/compiled-assets/javascripts/subscriptionsRedemptionPage.js 118 kB 0 B
./public/compiled-assets/javascripts/supporterPlusLandingPage.js 226 kB 0 B
./public/compiled-assets/javascripts/unsupportedBrowserStyles.js 20 B 0 B
./public/compiled-assets/javascripts/weeklySubscriptionCheckoutPage.js 160 kB 0 B
./public/compiled-assets/javascripts/weeklySubscriptionLandingPage.js 88 kB 0 B
./public/compiled-assets/webpack/136.js 2.17 kB 0 B
./public/compiled-assets/webpack/186.js 3.35 kB 0 B
./public/compiled-assets/webpack/187.js 21.7 kB 0 B
./public/compiled-assets/webpack/3.js 19.2 kB 0 B
./public/compiled-assets/webpack/311.js 40.1 kB 0 B
./public/compiled-assets/webpack/344.js 2.01 kB 0 B
./public/compiled-assets/webpack/397.js 10.2 kB 0 B
./public/compiled-assets/webpack/426.js 36.6 kB 0 B
./public/compiled-assets/webpack/643.js 22.4 kB 0 B
./public/compiled-assets/webpack/706.js 107 kB 0 B
./public/compiled-assets/webpack/754.js 9.96 kB 0 B
./public/compiled-assets/webpack/847.js 26 kB 0 B
./public/compiled-assets/webpack/checkout.js 14.3 kB 0 B
./public/compiled-assets/webpack/GuardianAdLiteLanding.js 9.05 kB 0 B
./public/compiled-assets/webpack/oneTimeCheckout.js 9.96 kB 0 B
./public/compiled-assets/webpack/ThankYou.js 1.08 kB 0 B

compressed-size-action

Copy link
Member

@tjmw tjmw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

I left one tiny suggestion, but not sure if it's useful here.

@@ -124,6 +120,10 @@ export function Events({ geoId }: Props) {
hashUrlSearchParams.toString(),
)}`;

if (!hashUrlSearchParams.has('p[meta_page_view_id]')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we'd want to use it here, but apparently .has takes an optional second arg which represents the expected value. So we could use that to verify not only that the key is set, but also that it has the value we want:

if (!hashUrlSearchParams.has('p[meta_page_view_id]', pageViewId)) {

https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/has

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea! I'll do this 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this 2nd parameter to my has() call but the type checking is now returning an error: Expected 1 arguments, but got 2, very odd as the type definition for has() includes an optional 2nd value parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-01-21 at 10 07 31

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This discussion highlights the same issue: microsoft/TypeScript#55569, the conclusion is has() is not adequately supported, in this situation the 'algorithm' can decide that a feature is not well supported by browsers and thus removes it: https://github.com/microsoft/TypeScript-DOM-lib-generator#when-the-type-is-missing. However the article suggests this happens if a feature is not supported by two or more browser engines, however the MDB for has() shows it is supported in all browsers latest versions: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/has so I wouldn't expect the algorithm to flag it as unsupported.

A temporary workaround could be to this to our any.d.ts file:

global {
  interface URLSearchParams {
    has(name: string, value?: any): boolean;
  }
}

@tjmw what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird! Yeah for me VSCode is happy, it looks like its using it's own dom types, but running yarn validate I'm seeing the same error. I can't see anything in our tsconfig which would determine the dom types used, maybe it's something we're getting from @guardian/tsconfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird! Yeah for me VSCode is happy, it looks like its using it's own dom types, but running yarn validate I'm seeing the same error. I can't see anything in our tsconfig which would determine the dom types used, maybe it's something we're getting from @guardian/tsconfig?

Yeah I wondered whether there's a compatibility issue between our minimum supported browsers and the feature, I couldn't find where in the Typescript config we define minimum supported browser versions. I'll check @guardian/tsconfig now!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing in support-frontend/tsconfig.json the @guardian/tsconfig to indicate minumum browser versions supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to remember reading that the lib types are somehow derived from the target if not specified explicitly, which in our case is esnext (coming from @guardian/tsconfig). Esnext means the laces ecma script version supported by the version of TypeScript you're on, which for us is 5.1.6. I think the latest target supported by that version is ES2020 but I'm finding it hard to prove that.

@GHaberis GHaberis merged commit 8ba7a37 into main Jan 21, 2025
19 checks passed
@GHaberis GHaberis deleted the gh-event-test-hashUrlSearchParams branch January 21, 2025 11:56
@prout-bot
Copy link

Seen on PROD (merged by @GHaberis 8 minutes and 55 seconds ago)

Sentry Release: support-client-side, support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants