File tree Expand file tree Collapse file tree 3 files changed +30
-17
lines changed
src/client/packages/idom-client-react/src Expand file tree Collapse file tree 3 files changed +30
-17
lines changed Original file line number Diff line number Diff line change @@ -16,20 +16,15 @@ scheme for the project adheres to `Semantic Versioning <https://semver.org/>`__.
1616Unreleased
1717----------
1818
19- While this release doesn't warrant a minor version bump, the last release should have
20- been. Thus, to make up for that, this release will be a minor bump. It includes misc
21- bug fixes, and several feature adds, the most important of which is the addition of the
22- ``use_context `` hook.
23-
2419Added:
2520
2621- Support for keys in HTML fragments - :issue: `682 `
22+ - Use Context Hook - :pull: `585 `
2723
28- ** Merged Pull Requests **
24+ Fixed:
2925
30- - reset schedule_render_later flag after triggering - :pull: `688 `
31- - support keys in HTML fragments - :pull: `683 `
32- - Add Use Context Hook - :pull: `585 `
26+ - React warning about set state in unmounted component - :issue: `690 `
27+ - Missing reset of schedule_render_later flag - :pull: `688 `
3328
3429----
3530
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import ReactDOM from "react-dom";
33import htm from "htm" ;
44
55import { useJsonPatchCallback } from "./json-patch.js" ;
6- import { loadModelImportSource } from "./import-source.js" ;
6+ import { useImportSource } from "./import-source.js" ;
77import {
88 createElementAttributes ,
99 createElementChildren ,
@@ -101,14 +101,9 @@ function ImportedElement({ model }) {
101101 const layoutContext = React . useContext ( LayoutContext ) ;
102102
103103 const importSourceFallback = model . importSource . fallback ;
104- const [ importSource , setImportSource ] = React . useState ( null ) ;
104+ const importSource = useImportSource ( model . importSource ) ;
105105
106106 if ( ! importSource ) {
107- // load the import source in the background
108- loadModelImportSource ( layoutContext , model . importSource ) . then (
109- setImportSource
110- ) ;
111-
112107 // display a fallback if one was given
113108 if ( ! importSourceFallback ) {
114109 return html `< div /> ` ;
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+
13import {
24 createElementAttributes ,
35 createElementChildren ,
46} from "./element-utils.js" ;
57
6- export function loadModelImportSource ( layoutContext , importSource ) {
8+ export function useImportSource ( modelImportSource ) {
9+ const layoutContext = React . useContext ( LayoutContext ) ;
10+ const [ importSource , setImportSource ] = React . useState ( null ) ;
11+
12+ useEffect ( ( ) => {
13+ let unmounted = false ;
14+
15+ loadModelImportSource ( layoutContext , modelImportSource ) . then ( ( src ) => {
16+ if ( ! unmounted ) {
17+ setImportSource ( src ) ;
18+ }
19+ } ) ;
20+
21+ return ( ) => {
22+ unmounted = true ;
23+ } ;
24+ } , [ layoutContext , modelImportSource , setImportSource ] ) ;
25+
26+ return importSource ;
27+ }
28+
29+ function loadModelImportSource ( layoutContext , importSource ) {
730 return layoutContext
831 . loadImportSource ( importSource . source , importSource . sourceType )
932 . then ( ( module ) => {
You can’t perform that action at this time.
0 commit comments