diff --git a/examples/hello-world/src/App.tsx b/examples/hello-world/src/App.tsx
index a8a8fb1..eb18dd9 100644
--- a/examples/hello-world/src/App.tsx
+++ b/examples/hello-world/src/App.tsx
@@ -1 +1 @@
-export {default} from './suspense'
+export {default} from './lazy'
diff --git a/examples/hello-world/src/lazy/Cpn.tsx b/examples/hello-world/src/lazy/Cpn.tsx
new file mode 100644
index 0000000..d525148
--- /dev/null
+++ b/examples/hello-world/src/lazy/Cpn.tsx
@@ -0,0 +1,3 @@
+export default function Cpn() {
+ return
Cpn
+}
diff --git a/examples/hello-world/src/lazy/index.tsx b/examples/hello-world/src/lazy/index.tsx
new file mode 100644
index 0000000..971267c
--- /dev/null
+++ b/examples/hello-world/src/lazy/index.tsx
@@ -0,0 +1,19 @@
+import {Suspense, lazy} from 'react'
+
+function delay(promise) {
+ return new Promise((resolve) => {
+ setTimeout(() => {
+ resolve(promise)
+ }, 2000)
+ })
+}
+
+const Cpn = lazy(() => import('./Cpn').then((res) => delay(res)))
+
+export default function App() {
+ return (
+ loading}>
+
+
+ )
+}
diff --git a/examples/hello-world/src/suspense/index.tsx b/examples/hello-world/src/suspense/index.tsx
index 6ce2e81..17b424d 100644
--- a/examples/hello-world/src/suspense/index.tsx
+++ b/examples/hello-world/src/suspense/index.tsx
@@ -19,14 +19,21 @@ function fetchData(id, timeout) {
export default function App() {
return (
- loading}>
-
+ Out loading}>
+
+ Inner loading}>
+
+
)
}
-function Child() {
- const {data} = use(fetchData(1, 1000))
+function Child({id, timeout}) {
+ const {data} = use(fetchData(id, timeout))
- return {data}
+ return (
+
+ {id}:{data}
+
+ )
}
diff --git a/packages/react-reconciler/src/begin_work.rs b/packages/react-reconciler/src/begin_work.rs
index aba2024..4d32fd0 100644
--- a/packages/react-reconciler/src/begin_work.rs
+++ b/packages/react-reconciler/src/begin_work.rs
@@ -57,42 +57,44 @@ pub fn begin_work(
};
// TODO work with suspense
- // let current = { work_in_progress.borrow().alternate.clone() };
+ let current = { work_in_progress.borrow().alternate.clone() };
- // if current.is_some() {
- // let current = current.clone().unwrap();
- // let old_props = current.borrow().memoized_props.clone();
- // let old_type = current.borrow()._type.clone();
- // let new_props = work_in_progress.borrow().pending_props.clone();
- // let new_type = work_in_progress.borrow()._type.clone();
- // if !Object::is(&old_props, &new_props) || !Object::is(&old_type, &new_type) {
- // unsafe { DID_RECEIVE_UPDATE = true }
- // } else {
- // let has_scheduled_update_or_context =
- // check_scheduled_update_or_context(current.clone(), render_lane.clone());
- // // The current fiber lane is not included in render_lane
- // // TODO context
- // if !has_scheduled_update_or_context {
- // unsafe { DID_RECEIVE_UPDATE = false }
- // match work_in_progress.borrow().tag {
- // WorkTag::ContextProvider => {
- // let new_value = derive_from_js_value(
- // &work_in_progress.borrow().memoized_props,
- // "value",
- // );
- // let context =
- // derive_from_js_value(&work_in_progress.borrow()._type, "_context");
- // push_provider(&context, new_value);
- // }
- // _ => {}
- // }
- // return Ok(bailout_on_already_finished_work(
- // work_in_progress,
- // render_lane,
- // ));
- // }
- // }
- // }
+ if current.is_some() {
+ let current = current.clone().unwrap();
+ let old_props = current.borrow().memoized_props.clone();
+ let old_type = current.borrow()._type.clone();
+ let new_props = work_in_progress.borrow().pending_props.clone();
+ let new_type = work_in_progress.borrow()._type.clone();
+ if !Object::is(&old_props, &new_props) || !Object::is(&old_type, &new_type) {
+ unsafe { DID_RECEIVE_UPDATE = true }
+ } else {
+ let has_scheduled_update_or_context =
+ check_scheduled_update_or_context(current.clone(), render_lane.clone());
+ // The current fiber lane is not included in render_lane
+ // TODO context
+ if !has_scheduled_update_or_context
+ && current.borrow().tag != WorkTag::SuspenseComponent
+ {
+ unsafe { DID_RECEIVE_UPDATE = false }
+ match work_in_progress.borrow().tag {
+ WorkTag::ContextProvider => {
+ let new_value = derive_from_js_value(
+ &work_in_progress.borrow().memoized_props,
+ "value",
+ );
+ let context =
+ derive_from_js_value(&work_in_progress.borrow()._type, "_context");
+ push_provider(&context, new_value);
+ }
+ _ => {}
+ }
+ return Ok(bailout_on_already_finished_work(
+ work_in_progress,
+ render_lane,
+ ));
+ }
+ }
+ }
work_in_progress.borrow_mut().lanes = Lane::NoLane;
// if current.is_some() {
@@ -117,9 +119,25 @@ pub fn begin_work(
WorkTag::Fragment => Ok(update_fragment(work_in_progress.clone())),
WorkTag::SuspenseComponent => Ok(update_suspense_component(work_in_progress.clone())),
WorkTag::OffscreenComponent => Ok(update_offscreen_component(work_in_progress.clone())),
+ WorkTag::LazyComponent => update_lazy_component(work_in_progress.clone(), render_lane),
};
}
+fn update_lazy_component(
+ work_in_progress: Rc>,
+ render_lane: Lane,
+) -> Result