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

Update naming of Metric object enums to be consistent #247

Merged
merged 3 commits into from
Jul 24, 2022

Conversation

philipwalton
Copy link
Member

This PR updates all enum values exposed on the Metric object to use naming conventions consistent with those recommended by the TAG's Design Principles guide (i.e. kebab case).

This change updates two of the navigationType values, 'back_forward' and 'back_forward_cache', and renames them to 'back-forward' and 'back-forward-cache' (changing them from snake case to kebab case). Note that this PR also includes other renames as well, but none of those names were from released versions, so they are not a use-visible change.

Note that technically this is a breaking change since the navigationType property was released in v3.0.0-beta.0, but it is only a breaking change for users of the v3 beta versions. It is not a breaking change for users upgrading from version 2 or older.

README.md Outdated Show resolved Hide resolved
Comment on lines -67 to +68
navigationType: NavigationTimingType | 'back_forward_cache' | 'prerender' | undefined;
navigationType: 'navigate' | 'reload' | 'back-forward' | 'back-forward-cache' | 'prerender';
Copy link
Member

Choose a reason for hiding this comment

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

On line 64 you mention undefined but have remove that from here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, I updated the code so the undefined would no longer be possible.

Note, I don't think it was ever technically possible before, but according to the type logic is was possible since getNavigationEntry() can return undefined in cases where the browser doesn't support any performance APIs at all (see #185). However, browsers that do not support any performance APIs should not be able to get this far in the code to ever fire these callbacks (all onXXX() functions are gated on some sort of performance API support), which is why I say I don't think it's technically possible, at least not in any browser I'm aware of.

I made the change because I thought it was much riskier to have the type definition advertise that it is possible to get undefined here, and I didn't want developers to be coding defensively for something that I don't think can happen (and now definitely can't because the default is 'navigate').

metric = initMetric('TTFB', 0);
report = bindReporter(onReport, metric, thresholds, opts!.reportAllChanges);
report(true);
// Only report TTFB after bfcache restores if a `navigation` entry
Copy link
Member Author

@philipwalton philipwalton Jul 24, 2022

Choose a reason for hiding this comment

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

@tunetheweb FYI: I moved this onBFCacheRestore() call inside the check for the navigation entry to ensure that a TTFB metric wasn't reported after a bfcache restore in cases where the browser doesn't support the Navigation Timing API at all.

This still wouldn't affect cases where navigationType was undefined because in bfcache restores the type is set to back-forward-cache, but I do think it was a bug since browsers like Opera mini in extreme data saver mode might have run into this (if Opera mini supports bfcache, not sure about that..).

I checked all the other functions to, but they were all fine since they're gated on support for PerformanceObserver.

@philipwalton philipwalton merged commit 535a69f into next Jul 24, 2022
@philipwalton philipwalton deleted the api-consistency branch July 24, 2022 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants