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

fix(bcd): show previous version in range when feature was removed #7589

Merged
merged 3 commits into from
Nov 16, 2022

Conversation

danielhjacobs
Copy link
Contributor

@danielhjacobs danielhjacobs commented Nov 15, 2022

Summary

Fixes #6667

Problem

The version range showed the version where support was removed as well, which was confusing.

Solution

Get version before that version using a helper function, and show that version number instead.


Screenshots

Before

https://developer.mozilla.org/en-US/docs/Web/API/DocumentType#browser_compatibility

Screenshot from 2022-11-16 11-59-04

After

http://localhost:3000/en-US/docs/Web/API/DocumentType#browser_compatibility

Screenshot from 2022-11-16 11-50-41

@foolip
Copy link
Contributor

foolip commented Nov 15, 2022

That looks much better!

@caugner caugner marked this pull request as draft November 15, 2022 22:43
@danielhjacobs danielhjacobs changed the title fix(bcd): Don't show exact version when a feature was removed in version range fix(bcd): Don't show exact version when feature was removed in range Nov 16, 2022
@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Nov 16, 2022
@danielhjacobs danielhjacobs force-pushed the use_earlier_version_when_removed branch from 5d1d34f to afda565 Compare November 16, 2022 16:53
@danielhjacobs danielhjacobs marked this pull request as ready for review November 16, 2022 16:56
@danielhjacobs danielhjacobs requested review from foolip and caugner and removed request for foolip November 16, 2022 17:04
@danielhjacobs danielhjacobs force-pushed the use_earlier_version_when_removed branch from afda565 to 78ecb21 Compare November 16, 2022 17:21
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

LGTM, just two nits (I think).

@caugner caugner added 🧑‍🤝‍🧑 community contributions by our wonderful community browser-compat issues related to the browser compatibility data tables (BCD) labels Nov 16, 2022
@github-actions github-actions bot removed the browser-compat issues related to the browser compatibility data tables (BCD) label Nov 16, 2022
@caugner caugner changed the title fix(bcd): Don't show exact version when feature was removed in range fix(bcd): show previous version in range when feature was removed Nov 16, 2022
@caugner caugner merged commit 9a46d54 into mdn:main Nov 16, 2022
@caugner caugner added the browser-compat issues related to the browser compatibility data tables (BCD) label Nov 16, 2022
@caugner
Copy link
Contributor

caugner commented Nov 16, 2022

Thank you @danielhjacobs! 🎉

@danielhjacobs danielhjacobs deleted the use_earlier_version_when_removed branch November 16, 2022 20:54
@caugner
Copy link
Contributor

caugner commented Nov 17, 2022

Hm, for some reason it doesn't work on prod (although deployed): https://developer.mozilla.org/en-US/docs/Web/API/DocumentType#browser_compatibility 🤔

@caugner
Copy link
Contributor

caugner commented Nov 17, 2022

Hm, for some reason it doesn't work on prod (although deployed): https://developer.mozilla.org/en-US/docs/Web/API/DocumentType#browser_compatibility 🤔

It looks like browser.releases only has the last 3 entries on prod:
image

That's because retired releases are not added to the bcd.json:

yari/build/cli.ts

Lines 199 to 211 in 9a46d54

// The BCD data object contains a bunch of data we don't need in the
// React component that loads the `bcd.json` file and displays it.
// The `.releases` block contains information about browsers (e.g
// release dates) and that part has already been extracted and put
// next to each version number where appropriate.
// Therefore, we strip out all "retired" releases.
if (key === "releases") {
return Object.fromEntries(
Object.entries(value as bcd.ReleaseStatement).filter(
([, v]) => v.status !== "retired"
)
);
}

edit: And the BCD data itself is extracted here:

function _buildSpecialBCDSection(): [BCDSection] {
// First extract a map of all release data, keyed by (normalized) browser
// name and the versions.
// You'll have a map that looks like this:
//
// 'chrome_android': {
// '28': {
// release_date: '2012-06-01',
// release_notes: '...',
// ...
//
// The reason we extract this to a locally scoped map, is so we can
// use it to augment the `__compat` blocks for the latest version
// when (if known) it was added.
const browserReleaseData = new Map();
for (const [name, browser] of Object.entries(browsers)) {
const releaseData = new Map();
for (const [version, data] of Object.entries(browser.releases || [])) {
if (data) {
releaseData.set(version, data);
}
}
browserReleaseData.set(name, releaseData);
}
for (const block of _extractCompatBlocks(data)) {
for (const [browser, originalInfo] of Object.entries(block.support)) {
// `originalInfo` here will be one of the following:
// - a single simple_support_statement:
// { version_added: 42 }
// - an array of simple_support_statements:
// [ { version_added: 42 }, { prefix: '-moz', version_added: 35 } ]
//
// Standardize the first version to an array of one, so we don't have
// to deal with two different forms below
const infos: SimpleSupportStatementWithReleaseDate[] = Array.isArray(
originalInfo
)
? originalInfo
: [originalInfo];
for (const infoEntry of infos) {
const added =
typeof infoEntry.version_added === "string" &&
infoEntry.version_added.startsWith("≤")
? infoEntry.version_added.slice(1)
: infoEntry.version_added;
if (browserReleaseData.has(browser)) {
if (browserReleaseData.get(browser).has(added)) {
infoEntry.release_date = browserReleaseData
.get(browser)
.get(added).release_date;
}
}
}
infos.sort((a, b) =>
_compareVersions(_getFirstVersion(b), _getFirstVersion(a))
);
block.support[browser] = infos;
}
}
if (hasMultipleQueries) {
title = query;
id = query;
isH3 = true;
}
return [
{
type: "browser_compatibility",
value: {
title,
id,
isH3,
data,
query,
browsers,
},
},
];
}

@danielhjacobs
Copy link
Contributor Author

danielhjacobs commented Nov 17, 2022

infos.sort((a, b) =>
_compareVersions(_getFirstVersion(b), _getFirstVersion(a))
);

Well that function seems useful, could avoid the compare-versions dependency by re-using it.

I assume the right thing to do then would be to add version_supported_last (as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=1417902#c1) to infoEntry around here:

infoEntry.release_date = browserReleaseData
.get(browser)
.get(added).release_date;

Also adding version_supported_last?: string here:

interface SimpleSupportStatementWithReleaseDate
extends bcd.SimpleSupportStatement {
release_date?: string;
}

At that part of the code, are all the browser releases available in browsers?

If so, that would the right place for this function. I assume browsers[browser] would be the BrowserStatement and infoEntry?.version_removed ?? null would be the VersionValue, but I'm not certain:

export function getPreviousVersion(
version: BCD.VersionValue,
browser: BCD.BrowserStatement
): BCD.VersionValue {
if (browser && typeof version === "string") {
const browserVersions = Object.keys(browser["releases"]).sort(
compareVersions
);
const currentVersionIndex = browserVersions.indexOf(version);
if (currentVersionIndex > 0) {
return browserVersions[currentVersionIndex - 1];
}
}
return version;
}

Then switching this to const removed = currentSupport?.version_supported_last ?? null; (possibly changing the variable name there and where it's used to lastSupported):

const removed = getPreviousVersion(
currentSupport?.version_removed ?? null,
browser
);

@danielhjacobs
Copy link
Contributor Author

I do notice you're currently editing that part of the codebase in #7612

@danielhjacobs
Copy link
Contributor Author

Opened #7614

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser-compat issues related to the browser compatibility data tables (BCD) 🧑‍🤝‍🧑 community contributions by our wonderful community dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BCD tables include the version_removed in the version range
3 participants