Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2k
Help Understanding the Preact Codebase and Dev Workflow#4758
-
Hey, hi! I've reached out to a few people but haven’t received any replies. I thought this would be my last resort to ask for help. Here’s my question in simple terms:How do I understand the Preact codebase? To elaborate: I’ve found the source files for core methods like My plan was to:
However, that didn’t work — I ran into CORS issues, and couldn’t figure out how to correctly map the output to I also tried a similar approach with the React codebase — no luck there either. What really sparked my curiosity is seeing how Preact internally reuses logic — like implementing I’m eager to learn and dig deep into the internals of Preact. Any help or direction would mean a lot! Thanks so much for maintaining such a great library. |
BetaWas this translation helpful?Give feedback.
All reactions
There are two ways to work in this repository, you have thedemo/
folder which you can runnpm i && npm run dev
in. This will contain a live copy of the files within the repo so any console.log will show up. This is tested in browser etc as described in point 2.
Secondly you can develop through tests, inevery repository you can just look atpackage.json.scripts
to find out what commands you can run.npm run test:vitest
is one of ours.
I personally debug libraries withdemo/
and solve Preact specific issues with tests running, I write a new test and solve the issue.
- Where to start if i wanna learn the internals and understand the codebase?
it's a small code base, starting from the sta…
Replies: 4 comments 8 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
There are two ways to work in this repository, you have the Secondly you can develop through tests, inevery repository you can just look at I personally debug libraries with
it's a small code base, starting from the start is all you need I reckon, start from I don't know where you reached out but I didn't see anything, feel free to reach out to me on our slack. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks a lot!!!@JoviDeCroock I'll come back with an article like “Walkthrough: Building Your Own Preact” after I understand the concepts well. |
BetaWas this translation helpful?Give feedback.
All reactions
-
This might help you as wellhttps://www.puruvj.dev/blog/deep-dive-into-preact-source-code |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
I tried adding console.log at the start of the diff method and faced two issues:
|
BetaWas this translation helpful?Give feedback.
All reactions
-
|
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Now I can apply multiple I added |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
You can find information about Line 171 inb52475b
The children passed via |
BetaWas this translation helpful?Give feedback.
All reactions
-
@marvinhagemeister@JoviDeCroock Honestly, I don't know how you all understood the codebase. Will this version (https://github.com/preactjs/preact/tree/1.3.0) help us understand version 10? |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
No, when you try to understand a codebase it's best to consider a major version in isolation. Conceptually they will match but the implemented concepts will hugely differ. When you approach a codebase it's best to approach it principles first, i.e. what are we trying to do, we are creating a virtual ui representation and reflecting that to the DOM. That similar to updates,... In that world of creating a virtual representation we need to construct the tree depth first, when we hit a leaf we trampoline back up while comitting that subtree and move on to the sibling when one of those upper levels has siblings. |
BetaWas this translation helpful?Give feedback.
All reactions
-
useful for objects. but spread operators are not helpful to view DOM elements, right? correct me if i'm wrong. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Can you reply in the thread rather than in new messages every time please, also you can use |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
sure. let me check. |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #4757 on May 07, 2025 13:13.