File tree 3 files changed +30
-17
lines changed
src/client/packages/idom-client-react/src
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/>`__.
16
16
Unreleased
17
17
----------
18
18
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
-
24
19
Added:
25
20
26
21
- Support for keys in HTML fragments - :issue: `682 `
22
+ - Use Context Hook - :pull: `585 `
27
23
28
- ** Merged Pull Requests **
24
+ Fixed:
29
25
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 `
33
28
34
29
----
35
30
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import ReactDOM from "react-dom";
3
3
import htm from "htm" ;
4
4
5
5
import { useJsonPatchCallback } from "./json-patch.js" ;
6
- import { loadModelImportSource } from "./import-source.js" ;
6
+ import { useImportSource } from "./import-source.js" ;
7
7
import {
8
8
createElementAttributes ,
9
9
createElementChildren ,
@@ -101,14 +101,9 @@ function ImportedElement({ model }) {
101
101
const layoutContext = React . useContext ( LayoutContext ) ;
102
102
103
103
const importSourceFallback = model . importSource . fallback ;
104
- const [ importSource , setImportSource ] = React . useState ( null ) ;
104
+ const importSource = useImportSource ( model . importSource ) ;
105
105
106
106
if ( ! importSource ) {
107
- // load the import source in the background
108
- loadModelImportSource ( layoutContext , model . importSource ) . then (
109
- setImportSource
110
- ) ;
111
-
112
107
// display a fallback if one was given
113
108
if ( ! importSourceFallback ) {
114
109
return html `< div /> ` ;
Original file line number Diff line number Diff line change
1
+ import React from "react" ;
2
+
1
3
import {
2
4
createElementAttributes ,
3
5
createElementChildren ,
4
6
} from "./element-utils.js" ;
5
7
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 ) {
7
30
return layoutContext
8
31
. loadImportSource ( importSource . source , importSource . sourceType )
9
32
. then ( ( module ) => {
You can’t perform that action at this time.
0 commit comments