Skip to content

HMR does not work correctly in code sharing project #4398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
erkanarslan opened this issue Feb 26, 2019 · 4 comments
Closed

HMR does not work correctly in code sharing project #4398

erkanarslan opened this issue Feb 26, 2019 · 4 comments

Comments

@erkanarslan
Copy link

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 5.2.0
  • Cross-platform modules: 5.2.1
  • Android Runtime: 5.2.1
  • iOS Runtime: 5.2.0
  • Plugin(s): "nativescript-dev-webpack": "^0.20.0"

Describe the bug
I have an Angular code sharing project. HMR does not work properly. When I start the app, it loads the login page. I can change input attributes like placeholder and it is updated without page refresh. However, when I try to make a change in another page, page is reloaded and sometimes changes applied and sometimes not.

I tried changing a text in ActionBar. Page reloaded, text didn't change.
I tried removing an element from page. Page reloaded, element isn't removed.
I tried changing a function in .ts file. Page reloaded, function changed.

I think also HMR cannot handle angular directives like *ngIf and *ngFor.

To Reproduce
Create a code sharing project with navigation. Navigate to a page. Try changing content while hmr is enabled.

Expected behavior
Should update without reload.

Sample project
If you need, I can send you my whole project via email.

@vchimev
Copy link

vchimev commented Feb 27, 2019

Hey @erkanarslan,

Thank you for logging this.

Hot Module Replacement (HMR) is currently in Beta and for NativeScript-Angular projects, every change in .js/.ts, .css/.scss or .html file bootstraps the angular app (second table, latest column here).

This means that the native app is kept alive while the angular app inside starts again. For example,
in this sample app after navigating to the login component and making a change in it, the angular application bootstraps and shows the home component.

Improving the HMR feature is in our roadmap as the goal is to apply changes without bootstrap.
You could follow our progress in this tracking issue.

@Fatme Fatme self-assigned this Mar 5, 2019
@Fatme
Copy link
Contributor

Fatme commented Mar 5, 2019

Hi @erkanarslan,

I tried changing a text in ActionBar. Page reloaded, text didn't change.
I tried removing an element from page. Page reloaded, element isn't removed.

It is expected to bootstrap the angular app on change but the change should be applied and visible.

It'd be great appreciated if you can send us the whole project and exact steps so we can reproduce the problem on our side. You can share your files with me in the NativeScript Community Slack https://nativescriptcommunity.slack.com/ - my username is fatme

@vchimev
Copy link

vchimev commented Apr 25, 2019

I'm closing this issue due to inactivity. Please, reopen if still experience the problem along with a sample project.

@vchimev vchimev closed this as completed Apr 25, 2019
@tahir-jamil
Copy link

tahir-jamil commented May 23, 2019

hi updating the code from html will update the app but if i change something in typescript its not updating the application Please help
I am using nativescript angular with shared-project
main.ts

import { AppOptions } from "nativescript-angular/platform-common";

import { AppModule } from "./app/app.module";

let options: AppOptions = {};
if (module['hot']) {
    const hmrUpdate = require("nativescript-dev-webpack/hmr").hmrUpdate;

    options.hmrOptions = {
        moduleTypeFactory: () => AppModule,
        livesyncCallback: (platformReboot) => {
            console.log("HMR: Sync...")
            hmrUpdate();
            setTimeout(platformReboot, 0);
        },
    }
    hmrUpdate();

    // Path to your app module.
	// You might have to change it if your module is in a different place.
    module['hot'].accept(["./app/app.module"]);
}

// !!! Don't forget to pass the options when creating the platform
platformNativeScriptDynamic(options).bootstrapModule(AppModule);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants