-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Yoga 2.0.0 Beta Release Feedback #1320
Comments
I'm so excited that an npm package is getting attention! I was previously using the yoga-layout-prebuilt package. I could use advice on how to deal with the asynchronous nature of loadYoga(). In a simple project where all code is in one file, it is quite trivial. But in a real-world project where code is split into multiple files, what is the best way to deal with this? For example, I am writing a UI framework where multiple classes create nodes, and they need to be created synchronously. With a synchronous Yoga, this is a non-issue - you can just call Yoga.createNode() anywhere. I am thinking that the correct pattern is to have a global initialization method for my framework that calls loadYoga() and populates some variable such as MyFramework.yoga. Then, other classes create nodes using MyFramework.yoga.createNode(), assuming that the user of my framework called the global initialization method. Am I on the right track with this pattern, or is there a simpler way to handle this issue? Also, I noticed that 2.0.0-beta.1 doesn't work with Webpack and opened an issue here: #1321 |
If you have an environment that supports top-level await, I would recommend this pattern: // YogaInstance.js
import {loadYoga} from 'yoga-layout';
const YogaInstance = await loadYoga();
export default YogaInstance; // YogaUser.js
import Yoga from './YogaInstance';
... That way, you get a sync looking import, but the import system awaits for the async compilation. This also matches the behavior which is being specced for WebAssembly ESM integration. I hoped to use these semantics in the package, but the tooling compatibility wasn't there yet to make a library that could work out-of-the-box everywhere. So right now Yoga is a CommonJS interoperable JS module, embedding WebAssembly. In the future I would like to use proper WebAssembly ESM integration, for smaller binaries, sync interface, and streaming compilation of remote assets.
I think that is the rough solution if you cannot hide it behind the import system. Explicitly await somewhere, to cache an instance, so you can use it synchronously in the future. |
Bit disappointed with end of support for Yogakit. I use this yogakit wrapper in my projects and it works great, superb alternative to spring&strut and autolayout (lmao). The less broken version of SwiftUI is still only compatible with iOS 15 and up, so native rewrites of major apps with it are still years off. |
Hello, I'm very happy for the new direction of this project :-) I'm trying to use it with Next.js and had some issue to make them working together with other dependencies (like @vercel/analytics, next-auth, @headlessui/react, ...). Here's how I got it to work:
Example next.config.js: /** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
config.resolve.fallback = {
fs: false,
path: false,
};
return config;
},
};
module.exports = nextConfig; That said, it would be easier if we could leave moduleResolution to "node". Before trying the new version, I used the npm package "yoga-wasm-web" which didn't required to modify the default config. |
We released a (deprecated) |
I am going to split the WASM entrypoints into separate flavors for Node and Web. This will mean that a bundler targeting web will no longer reach code which attempts to import Node APIs. It also lets us make the Node entrypoint more efficient. Downside, is this goes further down the rabbit hole of relying on ESM resolution for per-platform code. |
This one is really annoying. At the same time ESM resolution really does give us a lot, and feels like a more forward-looking option. I think, we could maybe add documentation to use imports like |
I removed the beta label and marked the package as 2.0.0 now. |
Today we released Yoga 2.0.0-beta.1 across multiple channels. We've introduced a good number of changes, and would like feedback from users who are upgrading to it from older versions of Yoga.
Please leave a comment on this thread with any feedback from using the release.
The text was updated successfully, but these errors were encountered: