fix(webpack): Method View._onLiveSync context is always undefined #9839
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
What is the current behavior?
Method
View._onLiveSync
argument is always undefined.What is the new behavior?
Method
View._onLiveSync
argument is an object that implementsModuleContext
interface as expected.There is the need of context in a few places inside core modules. Few examples:
NativeScript/packages/core/ui/core/view/view-common.ts
Line 220 in 6941466
NativeScript/packages/core/ui/frame/frame-common.ts
Line 625 in f70081d
NativeScript/packages/core/application/index.ios.ts
Line 326 in 650ef59
Fixes/Implements/Closes #9837 .
This is my proposal for solving the issue related.
I took the liberty and replaced the old hot-loader approach of reading a file source and inject it in runtime, with a new function that contains code and the use of
toString()
call. This prints the source code of the function.UPDATED:
When hmr checks and retrieves modules that will apply changes to, a
context
argument will be set on__onLiveSync
call.There is also this case which runs if
injectHMRRuntime
is set tofalse
: https://github.com/DimitrisRK/NativeScript/blob/8855ca43735f6e6f6ffd3598ff3ea2d18d57fbbd/packages/webpack5/src/loaders/nativescript-hot-loader/index.ts#L30I wasn't sure if I should meddle with this code injection, so I left it intact.
@rigor789 Provided that we have found this patch okay or have applied all necessary changes, there might be a need for few changes in core modules too. Would it be alright to add those changes in the same PR?