New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update fails with scrambled DOM result #32
Comments
@mindplay-dk I'm sorry, now fre's key is not valid for components, and only ordinary element's key is currently supported. I've got a new idea here recently, and it's likely to come true soon. Or do you have any suggestions? |
Well, missing support for The main issue with this example is the DOM getting scrambled when main |
Halo, I've fixed this case now, and now It can get the correct rendering, but the diff result is still not the smallest. import { h, render, useState } from 'fre'
function App () {
const [arr, setArr] = useState(1)
return (
<div>
{new Array(arr).fill().map(i => (
<A val={i} key={i}/>
))}
<button onClick={() => setArr(arr+1)}>+</button>
</div>
)
}
function A (props) {
const [count, setCount] = useState(0)
return (
<div>
{count}
<button onClick={() => setCount(count + 1)}>+</button>
</div>
)
}
render(<App />, document.body) Or Could we study diff under fiber together? |
I tried updating my example to For example, if I do this: import * as fre from "fre";
console.log(fre); All I see in the console is It seems nothing is exported. The module build is maybe broken somehow? |
@mindplay-dk I found some bugs in my diff scheme again. I will write a new diff scheme during the holidays. Thank you for your use case. |
Ah ah! I found a JSX black magic to help solve this problem. |
Rewrite the diff schema, fix this case, upgrade to the latest version. |
The module works again - but now the elements aren't getting ordered correctly: Also, the You can fork/test my example for yourself here: https://codesandbox.io/s/determined-butterfly-uxuic (You should probably think about adding at least a basic test-suite - complex things like these have a tendency to break very easily, even with small changes. It can be very difficult to manually test for every possible thing that could break.) |
@mindplay-dk Agree. I have to admit that diff of the fiber list is really difficult. The main obstacle is the traversal of linked list. I need more time to study it carefully. No other libraries have similar logic expect React, that makes it difficult for me to emulate. Please wait for my reply, thanks! |
You're brave for even attempting this 💪😁 |
@mindplay-dk Hey ~ I'm on vacation now. I've refactor a new version. It looks like it can solve the problem now. This is not necessarily true, but the current way should be correct! |
Works better now, components get created/destroyed and maintain state correctly. 👍 There's one problem remaining in my example though: the Looks like two things are missing here:
You can see examples of both here. (Note that this implementation tracks whether a target element is an SVG node or not - something you may need to do later, if you want to support SVG. For reference, see also Preact's implementation here.) |
Ah……you're right. It's my oversight. I'm going to fix it and support svg, too. |
I fixed this and supported SVG…… but the size now reached 2kb!So sad 😢 |
2 KB for something like this is extremely good - focus on ensuring the project's integrity (tests!) and worry about optimizing for size later, when it's safe to do so. Refactoring for size at this stage, without tests, is extremely risky.
|
I really like testing framework T_T. but I'm not very good at it, but I think it's necessary. |
I've confirmed the fix in I'm closing this issue, thanks! (Let's continue the discussion about tests elsewhere.) |
I created the following small test example:
https://codesandbox.io/s/determined-butterfly-uxuic
At the top of the
index.jsx
file, you can swap the twoimport
statements betweenfre
andpreact
to see how this was supposed to work.With
preact
:With
fre
:As you can see, the app breaks down as soon as you try to add another counter.
(Is
key
actually supported? Without support forkey
-based diffing, it's very hard to make any meaningful use of stateful functional components...)The text was updated successfully, but these errors were encountered: