Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

HMR: Hot-updates generated for unchanged file #877

Closed
vakrilov opened this issue Apr 30, 2019 · 3 comments
Closed

HMR: Hot-updates generated for unchanged file #877

vakrilov opened this issue Apr 30, 2019 · 3 comments
Assignees
Projects

Comments

@vakrilov
Copy link
Contributor

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.3.4
  • Cross-platform modules: 5.3.1
  • Android Runtime: 5.3.1
  • iOS Runtime:5.3.1
  • Node.js: 10.15.1
  • nativescript-dev-webpack: ~0.21.0

Describe the bug
HMR generates hot-updates for files that are not changed.

To Reproduce

  1. Create and run with HMR
tns create test-app --tsc
cd test-app
tns run ios --hmr
  1. Change and save main-view-modes.ts file multiple times to generate hot updates.

Explore the generated hot-updates in platforms/ios/testapp/app/( the bundle.XXXX.hot-update.js files). All of them (except the first update) contain both main-view-modes.ts and ./main-page.ts.
The ./main-page.ts file wasn't changed, so it should not be re-generated and sent as a hot-update.

Expected behavior
Changes should be generated only for the changed files.

Why This Is Important
In the above example trying to use module.hot.accept(["./main-view-model"], () => { ... }) and handle view-model changes inside main-page.ts is not possible. Because the main-page.ts is also included in the hot-update it's changes bubble up and cannot be handled.

Possible Cause and Solution
According to ts-loader docs the transpileOnly flag should be enabled when using the loader with HMR.

Indeed setting transpileOnly: true in the ts-loader resolves the issue.

@vakrilov
Copy link
Contributor Author

vakrilov commented May 3, 2019

Acceptance criteria:

  • Check that after changing multiple times main-view-model.ts the generated hot-updates (bundle.XXXX.hot-update.js) do not contain "main-page.ts"
  • Check that after causing type error in TypeScript - the error is shown on the console. Example code that should cause the error: change main-page.ts:
page.bindingContext = new HelloWorldModel("test");
// Should cause `Expected 0 arguments, but got 1.` error.

@webleaf
Copy link

webleaf commented Jun 28, 2019

seems like transpileOnly option make impossible to use const enum
microsoft/TypeScript#16671 (comment)

@DimitarTachev
Copy link
Contributor

@webleaf,

By using transpileOnly: false, the enums are inlined compile time. In other words, color: Colors.red is directly replaced with color: "red" in your JavaScript code and you don't need the Colors enum available and exported in the JavaScript modules.

However, transpileOnly: true is not making impossible to use the const enums, it just does not inline them. In other words, you have to export the enums in order to make them available at runtime because in your JavaScript code you will still have color: Colors.red and the Colors enum should be available and exported in the JavaScript modules.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
CLI Team
  
Done
Development

No branches or pull requests

4 participants