File tree Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -1644,22 +1644,27 @@ function ImportedElement({ model }) {
16441644 }
16451645}
16461646
1647- function RenderImportedElement ( ) {
1647+ function RenderImportedElement ( { model , importSource } ) {
16481648 react . useContext ( LayoutConfigContext ) ;
16491649 const mountPoint = react . useRef ( null ) ;
16501650 const sourceBinding = react . useRef ( null ) ;
16511651
16521652 react . useEffect ( ( ) => {
16531653 sourceBinding . current = importSource . bind ( mountPoint . current ) ;
1654- return ( ) => {
1655- sourceBinding . current . unmount ( ) ;
1656- } ;
1654+ if ( ! importSource . data . unmountBeforeUpdate ) {
1655+ return sourceBinding . current . unmount ;
1656+ }
16571657 } , [ ] ) ;
16581658
16591659 // this effect must run every time in case the model has changed
1660- react . useEffect ( ( ) => sourceBinding . current . render ( model ) ) ;
1661-
1660+ react . useEffect ( ( ) => {
1661+ sourceBinding . current . render ( model ) ;
1662+ if ( importSource . data . unmountBeforeUpdate ) {
1663+ return sourceBinding . current . unmount ;
1664+ }
1665+ } ) ;
16621666
1667+ return html `< div ref =${ mountPoint } / > ` ;
16631668}
16641669
16651670function elementChildren ( modelChildren ) {
@@ -1717,6 +1722,7 @@ function loadImportSource$1(config, importSource) {
17171722 . then ( ( module ) => {
17181723 if ( typeof module . bind == "function" ) {
17191724 return {
1725+ data : importSource ,
17201726 bind : ( node ) => {
17211727 const binding = module . bind ( node , config ) ;
17221728 if (
Original file line number Diff line number Diff line change 44import responses
55
66from idom .web .utils import (
7+ module_name_suffix ,
78 resolve_module_exports_from_file ,
89 resolve_module_exports_from_source ,
910 resolve_module_exports_from_url ,
1314JS_FIXTURES_DIR = Path (__file__ ).parent / "js_fixtures"
1415
1516
17+ @pytest .mark .parametrize (
18+ "name, suffix" ,
19+ [
20+ ("module" , ".js" ),
21+ ("module.ext" , ".ext" ),
22+ ("module@x.y.z" , ".js" ),
23+ ("module.ext@x.y.z" , ".ext" ),
24+ ("@namespace/module" , ".js" ),
25+ ("@namespace/module.ext" , ".ext" ),
26+ ("@namespace/module@x.y.z" , ".js" ),
27+ ("@namespace/module.ext@x.y.z" , ".ext" ),
28+ ],
29+ )
30+ def test_module_name_suffix (name , suffix ):
31+ assert module_name_suffix (name ) == suffix
32+
33+
1634@responses .activate
1735def test_resolve_module_exports_from_file (caplog ):
1836 responses .add (
You can’t perform that action at this time.
0 commit comments