Skip to content

Commit 24feb43

Browse files
authored
Add lit.dev short links to dev mode warnings (#2119)
Adds a See https://lit.dev/msg/<code> for more information. string to all warnings logged by Lit's dev mode. Half of #2078. Other half is at lit/lit.dev#465.
1 parent eff2fbc commit 24feb43

File tree

5 files changed

+57
-52
lines changed

5 files changed

+57
-52
lines changed

.changeset/light-feet-tickle.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'lit-element': patch
3+
'lit-html': patch
4+
'@lit/reactive-element': patch
5+
---
6+
7+
Added lit.dev/msg links to dev mode warnings.

packages/lit-element/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export * from './decorators.js';
1212
console.warn(
1313
"The main 'lit-element' module entrypoint is deprecated. Please update " +
1414
"your imports to use the 'lit' package: 'lit' and 'lit/decorators.ts' " +
15-
"or import from 'lit-element/lit-element.ts'. See https://lit.dev/docs/releases/upgrade/#update-packages-and-import-paths for more information."
15+
"or import from 'lit-element/lit-element.ts'. See " +
16+
'https://lit.dev/msg/deprecated-import-path for more information.'
1617
);

packages/lit-element/src/lit-element.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const UpdatingElement = ReactiveElement;
5757

5858
const DEV_MODE = true;
5959

60-
let issueWarning: (warning: string) => void;
60+
let issueWarning: (code: string, warning: string) => void;
6161

6262
if (DEV_MODE) {
6363
// Ensure warnings are issued only 1x, even if multiple versions of Lit
@@ -66,7 +66,8 @@ if (DEV_MODE) {
6666
(globalThis.litIssuedWarnings ??= new Set());
6767

6868
// Issue a warning, if we haven't already.
69-
issueWarning = (warning: string) => {
69+
issueWarning = (code: string, warning: string) => {
70+
warning += ` See https://lit.dev/msg/${code} for more information.`;
7071
if (!issuedWarnings.has(warning)) {
7172
console.warn(warning);
7273
issuedWarnings.add(warning);
@@ -171,38 +172,32 @@ globalThis.litElementPlatformSupport?.({LitElement});
171172

172173
// DEV mode warnings
173174
if (DEV_MODE) {
175+
/* eslint-disable @typescript-eslint/no-explicit-any */
174176
// Note, for compatibility with closure compilation, this access
175177
// needs to be as a string property index.
176-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
177178
(LitElement as any)['finalize'] = function (this: typeof LitElement) {
178-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
179179
const finalized = (ReactiveElement as any).finalize.call(this);
180180
if (!finalized) {
181181
return false;
182182
}
183-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
184-
const warnRemoved = (obj: any, name: string) => {
183+
const warnRemovedOrRenamed = (obj: any, name: string, renamed = false) => {
185184
if (obj.hasOwnProperty(name)) {
186185
const ctorName = (typeof obj === 'function' ? obj : obj.constructor)
187186
.name;
188187
issueWarning(
188+
renamed ? 'renamed-api' : 'removed-api',
189189
`\`${name}\` is implemented on class ${ctorName}. It ` +
190-
`has been removed from this version of LitElement. See ` +
191-
`https://lit.dev/docs/releases/upgrade/#litelement ` +
192-
`for more information.`
190+
`has been ${renamed ? 'renamed' : 'removed'} ` +
191+
`in this version of LitElement.`
193192
);
194193
}
195194
};
196-
[`render`, `getStyles`].forEach((name: string) =>
197-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
198-
warnRemoved(this as any, name)
199-
);
200-
[`adoptStyles`].forEach((name: string) =>
201-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
202-
warnRemoved(this.prototype as any, name)
203-
);
195+
warnRemovedOrRenamed(this, 'render');
196+
warnRemovedOrRenamed(this, 'getStyles', true);
197+
warnRemovedOrRenamed(this.prototype, 'adoptStyles');
204198
return true;
205199
};
200+
/* eslint-enable @typescript-eslint/no-explicit-any */
206201
}
207202

208203
/**
@@ -242,8 +237,8 @@ export const _$LE = {
242237
(globalThis.litElementVersions ??= []).push('3.0.0-rc.3');
243238
if (DEV_MODE && globalThis.litElementVersions.length > 1) {
244239
issueWarning!(
240+
'multiple-versions',
245241
`Multiple versions of Lit loaded. Loading multiple versions ` +
246-
`is not recommended. See https://lit.dev/docs/tools/requirements/ ` +
247-
`for more information.`
242+
`is not recommended.`
248243
);
249244
}

packages/lit-html/src/lit-html.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ const ENABLE_SHADYDOM_NOPATCH = true;
1818
*/
1919
export const INTERNAL = true;
2020

21-
let issueWarning: (warning: string) => void;
21+
let issueWarning: (code: string, warning: string) => void;
2222

2323
if (DEV_MODE) {
2424
const issuedWarnings: Set<string | undefined> =
2525
(globalThis.litIssuedWarnings ??= new Set());
2626

2727
// Issue a warning, if we haven't already.
28-
issueWarning = (warning: string) => {
28+
issueWarning = (code: string, warning: string) => {
29+
warning += ` See https://lit.dev/msg/${code} for more information.`;
2930
if (!issuedWarnings.has(warning)) {
3031
console.warn(warning);
3132
issuedWarnings.add(warning);
3233
}
3334
};
3435

3536
issueWarning(
36-
`Lit is in dev mode. Not recommended for production! See ` +
37-
`https://lit.dev/docs/tools/development/` +
38-
`#development-and-production-builds for more information.`
37+
'dev-mode',
38+
`Lit is in dev mode. Not recommended for production!`
3939
);
4040
}
4141

@@ -1728,8 +1728,8 @@ globalThis.litHtmlPlatformSupport?.(Template, ChildPart);
17281728
(globalThis.litHtmlVersions ??= []).push('2.0.0-rc.4');
17291729
if (DEV_MODE && globalThis.litHtmlVersions.length > 1) {
17301730
issueWarning!(
1731-
`Multiple versions of Lit loaded. Loading multiple versions ` +
1732-
`is not recommended. See https://lit.dev/docs/tools/requirements/ ` +
1733-
`for more information.`
1731+
'multiple-versions',
1732+
`Multiple versions of Lit loaded. ` +
1733+
`Loading multiple versions is not recommended.`
17341734
);
17351735
}

packages/reactive-element/src/reactive-element.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let requestUpdateThenable: (name: string) => {
3636
) => void;
3737
};
3838

39-
let issueWarning: (warning: string) => void;
39+
let issueWarning: (code: string, warning: string) => void;
4040

4141
if (DEV_MODE) {
4242
// Ensure warnings are issued only 1x, even if multiple versions of Lit
@@ -45,17 +45,17 @@ if (DEV_MODE) {
4545
(globalThis.litIssuedWarnings ??= new Set());
4646

4747
// Issue a warning, if we haven't already.
48-
issueWarning = (warning: string) => {
48+
issueWarning = (code: string, warning: string) => {
49+
warning += ` See https://lit.dev/msg/${code} for more information.`;
4950
if (!issuedWarnings.has(warning)) {
5051
console.warn(warning);
5152
issuedWarnings.add(warning);
5253
}
5354
};
5455

5556
issueWarning(
56-
`Lit is in dev mode. Not recommended for production! See ` +
57-
`https://lit.dev/docs/tools/development/` +
58-
`#development-and-production-builds for more information.`
57+
'dev-mode',
58+
`Lit is in dev mode. Not recommended for production!`
5959
);
6060

6161
// Issue platform support warning.
@@ -64,10 +64,9 @@ if (DEV_MODE) {
6464
globalThis.reactiveElementPlatformSupport === undefined
6565
) {
6666
issueWarning(
67+
'polyfill-support-missing',
6768
`Shadow DOM is being polyfilled via \`ShadyDOM\` but ` +
68-
`the \`polyfill-support\` module has not been loaded. See ` +
69-
`https://lit.dev/docs/tools/requirements/#polyfills ` +
70-
`for more information.`
69+
`the \`polyfill-support\` module has not been loaded.`
7170
);
7271
}
7372

@@ -77,6 +76,7 @@ if (DEV_MODE) {
7776
_onrejected?: () => void
7877
) => {
7978
issueWarning(
79+
'request-update-promise',
8080
`The \`requestUpdate\` method should no longer return a Promise but ` +
8181
`does so on \`${name}\`. Use \`updateComplete\` instead.`
8282
);
@@ -615,17 +615,19 @@ export abstract class ReactiveElement
615615
this.elementStyles = this.finalizeStyles(this.styles);
616616
// DEV mode warnings
617617
if (DEV_MODE) {
618-
[`initialize`, `requestUpdateInternal`, `_getUpdateComplete`].forEach(
619-
(name: string) => {
620-
if (this.prototype.hasOwnProperty(name)) {
621-
issueWarning(
622-
`\`${name}\` is implemented on class ${this.name}. It ` +
623-
`has been removed from this version of \`ReactiveElement\`.` +
624-
` See the changelog at https://github.com/lit/lit/blob/main/packages/reactive-element/CHANGELOG.md`
625-
);
626-
}
618+
const warnRemovedOrRenamed = (name: string, renamed = false) => {
619+
if (this.prototype.hasOwnProperty(name)) {
620+
issueWarning(
621+
renamed ? 'renamed-api' : 'removed-api',
622+
`\`${name}\` is implemented on class ${this.name}. It ` +
623+
`has been ${renamed ? 'renamed' : 'removed'} ` +
624+
`in this version of LitElement.`
625+
);
627626
}
628-
);
627+
};
628+
warnRemovedOrRenamed('initialize');
629+
warnRemovedOrRenamed('requestUpdateInternal');
630+
warnRemovedOrRenamed('_getUpdateComplete', true);
629631
}
630632
return true;
631633
}
@@ -902,6 +904,7 @@ export abstract class ReactiveElement
902904
attrValue === undefined
903905
) {
904906
issueWarning(
907+
'undefined-attribute-value',
905908
`The attribute value for the ${name as string} property is ` +
906909
`undefined on element ${this.localName}. The attribute will be ` +
907910
`removed, but in the previous version of \`ReactiveElement\`, ` +
@@ -1093,17 +1096,15 @@ export abstract class ReactiveElement
10931096
);
10941097
if (shadowedProperties.length) {
10951098
issueWarning(
1099+
'class-field-shadowing',
10961100
`The following properties on element ${this.localName} will not ` +
10971101
`trigger updates as expected because they are set using class ` +
10981102
`fields: ${shadowedProperties.join(', ')}. ` +
10991103
`Native class fields and some compiled output will overwrite ` +
11001104
`accessors used for detecting changes. To fix this issue, ` +
11011105
`either initialize properties in the constructor or adjust ` +
11021106
`your compiler settings; for example, for TypeScript set ` +
1103-
`\`useDefineForClassFields: false\` in your \`tsconfig.json\`.` +
1104-
`See https://lit.dev/docs/components/properties/#declare and ` +
1105-
`https://lit.dev/docs/components/decorators/` +
1106-
`#avoiding-issues-with-class-fields for more information.`
1107+
`\`useDefineForClassFields: false\` in your \`tsconfig.json\`.`
11071108
);
11081109
}
11091110
}
@@ -1163,6 +1164,7 @@ export abstract class ReactiveElement
11631164
) >= 0
11641165
) {
11651166
issueWarning(
1167+
'change-in-update',
11661168
`Element ${this.localName} scheduled an update ` +
11671169
`(generally because a property was set) ` +
11681170
`after an update completed, causing a new update to be scheduled. ` +
@@ -1323,8 +1325,8 @@ if (DEV_MODE) {
13231325
(globalThis.reactiveElementVersions ??= []).push('1.0.0-rc.3');
13241326
if (DEV_MODE && globalThis.reactiveElementVersions.length > 1) {
13251327
issueWarning!(
1328+
'multiple-versions',
13261329
`Multiple versions of Lit loaded. Loading multiple versions ` +
1327-
`is not recommended. See https://lit.dev/docs/tools/requirements/ ` +
1328-
`for more information.`
1330+
`is not recommended.`
13291331
);
13301332
}

0 commit comments

Comments
 (0)