Skip to content

Commit dffec17

Browse files
authored
chore: warn when scoping suffix is set too late (#10781)
chore: log warning when using scoping suffix
1 parent ac83d60 commit dffec17

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/base/src/CustomElementsRegistry.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const isTagRegistered = (tag: string) => {
1919
return Definitions.has(tag);
2020
};
2121

22+
const hasRegisteredTags = () => {
23+
return Definitions.size > 0;
24+
};
25+
2226
const getAllRegisteredTags = () => {
2327
return [...Definitions.values()];
2428
};
@@ -93,6 +97,7 @@ const displayFailedRegistrations = () => {
9397
export {
9498
registerTag,
9599
isTagRegistered,
100+
hasRegisteredTags,
96101
getAllRegisteredTags,
97102
recordTagRegistrationFailure,
98103
};

packages/base/src/CustomElementsScopeUtils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { hasRegisteredTags } from "./CustomElementsRegistry.js";
12
import VersionInfo from "./generated/VersionInfo.js";
23

34
let suf: string;
@@ -16,7 +17,9 @@ const tagsCache = new Map<string, boolean>(); // true/false means the tag should
1617

1718
/**
1819
* Sets the suffix to be used for custom elements scoping, f.e. pass "demo" to get tags such as "ui5-button-demo".
19-
* Note: by default all tags starting with "ui5-" will be scoped, unless you change this by calling "setCustomElementsScopingRules"
20+
*
21+
* **Note:** By default all tags starting with "ui5-" will be scoped, unless you change this by calling "setCustomElementsScopingRules"
22+
* **Note:** Setting the scoping suffix must be done before importing any components.
2023
*
2124
* @public
2225
* @param suffix The scoping suffix
@@ -26,6 +29,11 @@ const setCustomElementsScopingSuffix = (suffix: string) => {
2629
throw new Error("Only alphanumeric characters and dashes allowed for the scoping suffix");
2730
}
2831

32+
if (hasRegisteredTags()) {
33+
// eslint-disable-next-line no-console
34+
console.warn("Setting the scoping suffix must be done before importing any components. For proper usage, read the scoping section: https://github.com/SAP/ui5-webcomponents/blob/main/docs/2-advanced/06-scoping.md.");
35+
}
36+
2937
suf = suffix;
3038
};
3139

0 commit comments

Comments
 (0)