feat(compiler-cli): Adds diagnostic for misconfigured @defer triggers#64069
feat(compiler-cli): Adds diagnostic for misconfigured @defer triggers#64069SkyZeroZx wants to merge 1 commit intoangular:mainfrom
Conversation
|
Curious if it's a real use case, I can't find something like this internally or externally? |
...ges/compiler-cli/src/ngtsc/typecheck/extended/checks/defer_trigger_misconfiguration/index.ts
Show resolved
Hide resolved
...ges/compiler-cli/src/ngtsc/typecheck/extended/checks/defer_trigger_misconfiguration/index.ts
Outdated
Show resolved
Hide resolved
...ges/compiler-cli/src/ngtsc/typecheck/extended/checks/defer_trigger_misconfiguration/index.ts
Outdated
Show resolved
Hide resolved
...ges/compiler-cli/src/ngtsc/typecheck/extended/checks/defer_trigger_misconfiguration/index.ts
Outdated
Show resolved
Hide resolved
I haven't found any similar cases publicly, but there are similar rules in EsLint, such as not having the same trigger as "main" and "prefetch". For the specific case of a main timer being less than a prefetch timer, I've seen it in some private codebases. |
0bb223a to
2042592
Compare
|
Thanks, let's merge it, please fix the lint warning |
2042592 to
e8beaa4
Compare
|
I did git push -f wrong, I'll fix it. Edit : Fixed, also fixed the linter warning |
b45cc4e to
f56ce83
Compare
| @Component({ | ||
| template: ` | ||
| <button #loadBtn>Load</button> | ||
| @defer (on interaction(loadBtn)) { | ||
| <large-component /> | ||
| } | ||
| ` | ||
| }) |
There was a problem hiding this comment.
I kinda feel like it would be valuable to have good and bad examples,
like
Don't to this:
```typescript
@Component({
template: `
<button #loadBtn>Load</button>
@defer (on interaction(loadBtn) prefetch on timer(500ms)) {
<large-component />
}
`
})do this:
@Component({
template: `
<button #loadBtn>Load</button>
@defer (on interaction(loadBtn)) {
<large-component />
}
`
})There was a problem hiding this comment.
The first example is not part of the diagnosis since we have no way of knowing where in the UI the user places it, and it’s something like rendering a footer at the end of a large list. It would be a matter of extending the diagnosis if needed.
But I do agree with adding more examples I’ll review and update it.
Updated documentation with more examples
Warns when @defer blocks define unreachable or redundant triggers, such as multiple main triggers, ineffective prefetches, or timer delays not scheduled before rendering.
f56ce83 to
15fa599
Compare
|
This PR was merged into the repository. The changes were merged into the following branches:
|
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Introduces a new diagnostic to detect unreachable or redundant trigger configurations in
@deferblocks, improving error reporting and developer feedback for template misconfigurations.Show warning
Case
@defer (on immediate; prefetch on idle) { <my-cmp /> }Message
Case
@deferon timer(100ms); prefetch on timer(3000ms) { <my-cmp /> }Message
@defer (on viewport; prefetch on viewport) { <my-cmp /> }Message
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #52739
What is the new behavior?
Does this PR introduce a breaking change?
Other information