Skip to content

Commit

Permalink
Warn for ARIA typos on custom elements (#26523)
Browse files Browse the repository at this point in the history
Normally we allow any attribute/property on custom elements. However
it's a shared namespace. The `aria-` namespace applies to all generic
elements which are shared with custom elements. So arguably adding
custom extensions there is a really bad idea since it can conflict with
future additions.

It's possible there is a new standard one that's polyfilled by a custom
element but the same issue applies to React in general that we might
warn for very new additions so we just have to be quick on that.

cc @josepharhar

DiffTrain build for [1a1d61f](1a1d61f)
  • Loading branch information
sebmarkbage committed Mar 30, 2023
1 parent b964e2e commit dd1749c
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 147 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
73deff0d5162160c0aafa5cd0b87e11143fe9938
1a1d61fed98a02c9b1bac029d0bc11c3e4db896d
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -9688,7 +9688,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-modern-6ef7b87a",
version: "18.3.0-www-modern-132fb191",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1304 = {
Expand Down Expand Up @@ -9719,7 +9719,7 @@ var internals$jscomp$inline_1304 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-6ef7b87a"
reconcilerVersion: "18.3.0-www-modern-132fb191"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1305 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
12 changes: 2 additions & 10 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6625,7 +6625,7 @@ function validateProperty$1(tagName, name) {
return true;
}

function warnInvalidARIAProps(type, props) {
function validateProperties$2(type, props) {
{
var invalidProps = [];

Expand Down Expand Up @@ -6661,14 +6661,6 @@ function warnInvalidARIAProps(type, props) {
}
}

function validateProperties$2(type, props) {
if (isCustomComponent(type, props)) {
return;
}

warnInvalidARIAProps(type, props);
}

var didWarnValueNull = false;
function validateProperties$1(type, props) {
{
Expand Down Expand Up @@ -39622,7 +39614,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-classic-0bf83ba8";
var ReactVersion = "18.3.0-www-classic-3fd40c97";

function createPortal$1(
children,
Expand Down
12 changes: 2 additions & 10 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -6406,7 +6406,7 @@ function validateProperty$1(tagName, name) {
return true;
}

function warnInvalidARIAProps(type, props) {
function validateProperties$2(type, props) {
{
var invalidProps = [];

Expand Down Expand Up @@ -6442,14 +6442,6 @@ function warnInvalidARIAProps(type, props) {
}
}

function validateProperties$2(type, props) {
if (isCustomComponent(type, props)) {
return;
}

warnInvalidARIAProps(type, props);
}

var didWarnValueNull = false;
function validateProperties$1(type, props) {
{
Expand Down Expand Up @@ -33645,7 +33637,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-modern-6ef7b87a";
var ReactVersion = "18.3.0-www-modern-132fb191";

function createPortal$1(
children,
Expand Down
62 changes: 27 additions & 35 deletions compiled/facebook-www/ReactDOMServer-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (__DEV__) {
var React = require("react");
var ReactDOM = require("react-dom");

var ReactVersion = "18.3.0-www-classic-67d0ef6c";
var ReactVersion = "18.3.0-www-classic-609488e0";

// This refers to a WWW module.
var warningWWW = require("warning");
Expand Down Expand Up @@ -773,31 +773,6 @@ function checkControlledValueProps(tagName, props) {
}
}

function isCustomComponent(tagName, props) {
if (tagName.indexOf("-") === -1) {
return typeof props.is === "string";
}

switch (tagName) {
// These are reserved SVG and MathML elements.
// We don't mind this list too much because we expect it to never grow.
// The alternative is to track the namespace in a few places which is convoluted.
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
case "annotation-xml":
case "color-profile":
case "font-face":
case "font-face-src":
case "font-face-uri":
case "font-face-format":
case "font-face-name":
case "missing-glyph":
return false;

default:
return true;
}
}

var ariaProperties = {
"aria-current": 0,
// state
Expand Down Expand Up @@ -928,7 +903,7 @@ function validateProperty$1(tagName, name) {
return true;
}

function warnInvalidARIAProps(type, props) {
function validateProperties$2(type, props) {
{
var invalidProps = [];

Expand Down Expand Up @@ -964,14 +939,6 @@ function warnInvalidARIAProps(type, props) {
}
}

function validateProperties$2(type, props) {
if (isCustomComponent(type, props)) {
return;
}

warnInvalidARIAProps(type, props);
}

var didWarnValueNull = false;
function validateProperties$1(type, props) {
{
Expand Down Expand Up @@ -1001,6 +968,31 @@ function validateProperties$1(type, props) {
}
}

function isCustomComponent(tagName, props) {
if (tagName.indexOf("-") === -1) {
return typeof props.is === "string";
}

switch (tagName) {
// These are reserved SVG and MathML elements.
// We don't mind this list too much because we expect it to never grow.
// The alternative is to track the namespace in a few places which is convoluted.
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
case "annotation-xml":
case "color-profile":
case "font-face":
case "font-face-src":
case "font-face-uri":
case "font-face-format":
case "font-face-name":
case "missing-glyph":
return false;

default:
return true;
}
}

// When adding attributes to the HTML or SVG allowed attribute list, be sure to
// also add them to this module to ensure casing and incorrect name
// warnings.
Expand Down
62 changes: 27 additions & 35 deletions compiled/facebook-www/ReactDOMServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (__DEV__) {
var React = require("react");
var ReactDOM = require("react-dom");

var ReactVersion = "18.3.0-www-modern-cbdf727f";
var ReactVersion = "18.3.0-www-modern-609fee14";

// This refers to a WWW module.
var warningWWW = require("warning");
Expand Down Expand Up @@ -773,31 +773,6 @@ function checkControlledValueProps(tagName, props) {
}
}

function isCustomComponent(tagName, props) {
if (tagName.indexOf("-") === -1) {
return typeof props.is === "string";
}

switch (tagName) {
// These are reserved SVG and MathML elements.
// We don't mind this list too much because we expect it to never grow.
// The alternative is to track the namespace in a few places which is convoluted.
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
case "annotation-xml":
case "color-profile":
case "font-face":
case "font-face-src":
case "font-face-uri":
case "font-face-format":
case "font-face-name":
case "missing-glyph":
return false;

default:
return true;
}
}

var ariaProperties = {
"aria-current": 0,
// state
Expand Down Expand Up @@ -928,7 +903,7 @@ function validateProperty$1(tagName, name) {
return true;
}

function warnInvalidARIAProps(type, props) {
function validateProperties$2(type, props) {
{
var invalidProps = [];

Expand Down Expand Up @@ -964,14 +939,6 @@ function warnInvalidARIAProps(type, props) {
}
}

function validateProperties$2(type, props) {
if (isCustomComponent(type, props)) {
return;
}

warnInvalidARIAProps(type, props);
}

var didWarnValueNull = false;
function validateProperties$1(type, props) {
{
Expand Down Expand Up @@ -1001,6 +968,31 @@ function validateProperties$1(type, props) {
}
}

function isCustomComponent(tagName, props) {
if (tagName.indexOf("-") === -1) {
return typeof props.is === "string";
}

switch (tagName) {
// These are reserved SVG and MathML elements.
// We don't mind this list too much because we expect it to never grow.
// The alternative is to track the namespace in a few places which is convoluted.
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
case "annotation-xml":
case "color-profile":
case "font-face":
case "font-face-src":
case "font-face-uri":
case "font-face-format":
case "font-face-name":
case "missing-glyph":
return false;

default:
return true;
}
}

// When adding attributes to the HTML or SVG allowed attribute list, be sure to
// also add them to this module to ensure casing and incorrect name
// warnings.
Expand Down
60 changes: 26 additions & 34 deletions compiled/facebook-www/ReactDOMServerStreaming-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,31 +770,6 @@ function checkControlledValueProps(tagName, props) {
}
}

function isCustomComponent(tagName, props) {
if (tagName.indexOf("-") === -1) {
return typeof props.is === "string";
}

switch (tagName) {
// These are reserved SVG and MathML elements.
// We don't mind this list too much because we expect it to never grow.
// The alternative is to track the namespace in a few places which is convoluted.
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
case "annotation-xml":
case "color-profile":
case "font-face":
case "font-face-src":
case "font-face-uri":
case "font-face-format":
case "font-face-name":
case "missing-glyph":
return false;

default:
return true;
}
}

var ariaProperties = {
"aria-current": 0,
// state
Expand Down Expand Up @@ -925,7 +900,7 @@ function validateProperty$1(tagName, name) {
return true;
}

function warnInvalidARIAProps(type, props) {
function validateProperties$2(type, props) {
{
var invalidProps = [];

Expand Down Expand Up @@ -961,14 +936,6 @@ function warnInvalidARIAProps(type, props) {
}
}

function validateProperties$2(type, props) {
if (isCustomComponent(type, props)) {
return;
}

warnInvalidARIAProps(type, props);
}

var didWarnValueNull = false;
function validateProperties$1(type, props) {
{
Expand Down Expand Up @@ -998,6 +965,31 @@ function validateProperties$1(type, props) {
}
}

function isCustomComponent(tagName, props) {
if (tagName.indexOf("-") === -1) {
return typeof props.is === "string";
}

switch (tagName) {
// These are reserved SVG and MathML elements.
// We don't mind this list too much because we expect it to never grow.
// The alternative is to track the namespace in a few places which is convoluted.
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
case "annotation-xml":
case "color-profile":
case "font-face":
case "font-face-src":
case "font-face-uri":
case "font-face-format":
case "font-face-name":
case "missing-glyph":
return false;

default:
return true;
}
}

// When adding attributes to the HTML or SVG allowed attribute list, be sure to
// also add them to this module to ensure casing and incorrect name
// warnings.
Expand Down
Loading

0 comments on commit dd1749c

Please sign in to comment.