aurelia / hot-module-reload

Core functionality for Aurelia's hot-module-reolad (HMR) capabilities, which is shared by all loaders and tools.
MIT License
25 stars 8 forks source link

Fix: missing resolvers when reloading a view #19

Closed rluba closed 5 years ago

rluba commented 6 years ago

recreateView creates a new container but did not copy the resolvers from the old container. This caused local DI instances (eg. injected into the controller via NewInstance.of) to be missing.

This fixes aurelia/validation#469, at least the HMR issue described by @alexdresko.

Here's a concrete example using a state component (for routing) and it’s view:

Component

@inject(NewInstance.of(ValidationController))
export class EditState {
    constructor(validator) {
        this.validator = validator;
        }
…
}

View

<template>
    <input type="number" name="something" value.bind="something & validate">
</template>

This state initially loads correctly, but when modifying the view, ValidateBindingBehaviorBase throws because it can’t locate the ValidationController because the corresponding resolver is missing from the view’s new container that’s created by HMR.

I’m relatively new to Aurelia, so I don’t know if the resolvers were not copied on purpose. @EisenbergEffect probably knows whether this was intended or not. If the resolvers should not be copied, then we need a different way to keep local DI instances during HMR.

rluba commented 5 years ago

Is there any reason why this fix has been unmerged for almost a full year?

EisenbergEffect commented 5 years ago

@rluba Somehow this must have gone under the radar. I'm merging now and adding to my release task list for this week. Apologies!

rluba commented 5 years ago

@EisenbergEffect Much appreciated, thanks!