WebReflection / hyperHTML

A Fast & Light Virtual DOM Alternative
ISC License
3.07k stars 112 forks source link

How to detect missing intents? #137

Closed mhoyer closed 6 years ago

mhoyer commented 6 years ago

I can write a very short and simple hyperHTML "application" like so:

const demo = hyperHTML.wire({})`<span>Demo: ${{NO_INTENT: 'NO_INTENT'}}</span>`;
hyperHTML.bind(document.body)`${demo}`;

Following the documentation about Content Values it is well defined how an Object is evaluated when used inside such string literal.

If the content is an Object, it's an explicit intent to perform one of the following operations:

  • if it has a text property, it will force whatever value as sanitized string, hence XSS free text content
  • if it has a html property, it will force whatever value as string, injecting it as HTML
  • if it has an any property, it will resolve whatever content it has compatibly with all understood types
  • if none of the following is true, hyperHTML will try to find out if it has the type defined in its registry.
  • In which case, it will pass along whatever value it is to the defined callback, and it will parse the resulting object against the types in this list.

But the last point does not clarify what happens if even a custom intent was not defined. Currently my example above procudes a wired DOM node output similar to:

<span>
  Demo:
  <!--_hyper: -1266042056;-->
</span>

So no content in the DOM and no error or warning on the console. Is this behavior on purpose or how should I handle such accidental issues?

A demo of this behavior: https://jsbin.com/dozedalucu/edit?html,output

WebReflection commented 6 years ago

You detect missing intents by not seeing expected results .

For portability and testability in isolation intents are fault tolerant on purpose.

I might notify via console.warn though, that seems a reasonable compromise.

Thoughts?

mhoyer commented 6 years ago

Sure, console.warn can help finding such issues. Maybe there should be some option to disable the warnings somehow (for production environments e.g.)? But that's up to you. ;-)

WebReflection commented 6 years ago

will put an hyperHTML.debug flag in V2.

Closing this as meant behavior for V1