emberjs / emberjs/ember.js

Improve error message when attempting to conditionally render a named block

Open
#21,036 0 comments 0 reactions 0 assignees View on GitHub
glimmervm
Dominant language
TypeScript
Stars
22.6k
Forks
4.2k
Avg merge
3d 12h
Merged PRs (30d)
15

Description

Currently when attempting to render a named block inside of another block the error message is not very clear.

Developers who are new to named blocks may assume that they work similarly to other glimmer template constructs, and assume that they can be conditionally rendered with an `if` or rendered within a looping construct like `each` or `each-in`.

Since many developers will discover this limitation of named-blocks by trying it and seeing this error, it would be good to have a more clear and helpful error message. Currently the message is `Unexpected named block nested in a normal block`.

I suggest that the error message should note what kind of block the named block was nested with in, and explain that this is not allowed/supported. The current phrasing "unexpected named block" does not fully communicate that this is actually not a supported use for named blocks, and the phrase "normal block" is not commonly used vernacular for referring to template blocks like `if`/`else`/`unless`/`each`/`each-in`. Thus it may not be clear to the developer reading the error message what the problem actually is or how to fix it.

Error message source:
https://github.com/glimmerjs/glimmer-vm/blob/b1a69add53b9b95bc4aea6099bb6bb69212be8e9/packages/%40glimmer/syntax/lib/v2-a/normalize.ts#L790

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.