@@ -61,6 +61,17 @@ export module DotNet {
6161 0 : new JSObject ( window , 0 ) ,
6262 } ;
6363
64+ cachedJSObjectsById [ 0 ] . _cachedFunctions . set ( 'import' , ( url : any ) => {
65+ // In most cases developers will want to resolve dynamic imports relative to the base HREF.
66+ // However since we're the one calling the import keyword, they would be resolved relative to
67+ // this framework bundle URL. Fix this by providing an absolute URL.
68+ if ( typeof url === 'string' && url . startsWith ( './' ) ) {
69+ url = document . baseURI + url . substr ( 2 ) ;
70+ }
71+
72+ return import ( /* webpackIgnore: true */ url ) ;
73+ } ) ;
74+
6475 let nextAsyncCallId = 1 ; // Start at 1 because zero signals "no response needed"
6576 let nextJsObjectId = 1 ; // Start at 1 because zero is reserved for "window"
6677
@@ -111,13 +122,13 @@ export module DotNet {
111122
112123 /**
113124 * Creates a JavaScript object reference that can be passed to .NET via interop calls.
114- *
125+ *
115126 * @param jsObject The JavaScript Object used to create the JavaScript object reference.
116127 * @returns The JavaScript object reference (this will be the same instance as the given object).
117128 * @throws Error if the given value is not an Object.
118129 */
119130 export function createJSObjectReference ( jsObject : any ) : any {
120- if ( jsObject instanceof Object ) {
131+ if ( jsObject && typeof jsObject === 'object' ) {
121132 if ( ! jsObject . hasOwnProperty ( JSObject . ID_KEY ) || cachedJSObjectsById [ nextJsObjectId ] !== jsObject ) {
122133 // The return value is not cached as a JSObjectReference, or is copied from an object that was, so we cache it as a new one
123134 cachedJSObjectsById [ nextJsObjectId ] = new JSObject ( jsObject , nextJsObjectId ) ;
@@ -132,7 +143,7 @@ export module DotNet {
132143
133144 /**
134145 * Disposes the JavaScript object reference associated with the given object.
135- *
146+ *
136147 * @param jsObject The JavaScript Object associated with the JavaScript object reference.
137148 */
138149 export function disposeJSObjectReference ( jsObject : any ) : void {
@@ -260,7 +271,7 @@ export module DotNet {
260271
261272 /**
262273 * Disposes the JavaScript object reference with the specified object ID.
263- *
274+ *
264275 * @param id The ID of the JavaScript object reference.
265276 */
266277 disposeJSObjectReferenceById,
0 commit comments