-
-
Notifications
You must be signed in to change notification settings - Fork 944
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
Manganis: Add Flag To Disable Folder Optimization #3293
base: main
Are you sure you want to change the base?
Conversation
It seems that the extra processing of the folder contents was a mistake / bad default, seems like we want to preserve contents by default and make optimization opt-in |
preserve_files
option for FolderAsset
What is the advantage of different default optimizations for folders vs files? I would expect these two to point to the same asset: const FOLDER: ASSET = asset!("/myfolder");
const ASSET: ASSET = asset!("/myfolder/asset.js");
rsx! {
script { src: "{FOLDER}/asset.js" }
script { src: ASSET }
} If asset optimization is breaking some files, we could make it opt in instead of opt out, or just fix the broken optimizations. Either way, I think we should be consistent about the default options regardless of how you import the asset |
I'm mixed between both approaches as one could say that the |
IMO asset-optimization ought to be opt-in in general. People wanted asset optimization will likely go looking for a setting and find it easily enough. People not wanting optimization are more likely to be surprised by it happening. |
…preserve-files
What if we:
According to semver, an addition should be on a minor release, not a patch, but I don't believe it would be an issue to include it on a patch. |
I think we should go with this direction. If you are able to make the changes today I can review + merge before EOD, hopefully unblocking the playground deployment! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but as per the comments in the PR we should retain the current default behavior and then decide if we want to change it in the next version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit unfortunate issue that the FolderAssetOption struct can't be expanded in a semver compatible way. We'd have to work around it somehow - either with a new feature flag or a new Options type. :(
I added a task to our notion to ensure that all public structs we export are marked non_exhaustive in the future so this doesn't happen again.
Otherwise looks good!
pub struct FolderAssetOptions { | ||
/// If the folder's files should be optimized. | ||
/// Defaults to true. | ||
optimize_files: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very unfortunate, but this struct was public and had no fields, meaning before this change it could be crafted and now it can't, meaning this technically doesn't follow semver.
We should have added a #[non_exhaustive] attribute on this strict.
To make this semver-safe we can add a new type that is non_exhaustive and use that as the FolderOptions going forward, marking the old one as deprecated. IE in the AssetOptions enum, we add a new variant that is something like "FolderLiteral" or something.
https://doc.rust-lang.org/cargo/reference/semver.html#struct-add-public-field-when-no-private
Take a look at our options if you can - we might be do something like converting FolderAssetOptions to PreservedFolder or something with a utility method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to avoid extra types and such and if this is only a temporary solution until 0.7, I'd be fine with it.
Originally the playground didn't need this PR but at one point, optimizations were enabled for the original asset/public folder breaking the workaround.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making it temporary is fine or forcing an opt-in with a feature flag might also work.
That way in the playground you can directly import manganis-core in the dep tree and enable the feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have gone with a new asset option type PreservedFolderAssetOptions
. The FolderAssetOptions
type has an into_preserved()
method which converts it into the preserved type.
Additionally, a trait FolderAsset
has been created so that cli-opt
can accept either asset options for a folder asset. All the temporary structs, methods, and traits are marked doc_hidden
to discourage use.
Let me know what you think.
The hasher test failed and I believe it was because the |
Yes, the hash is based on the serialized form of the enum. The hash itself changing between versions isn't an issue because it always comes from the macro. However, changing the structure of If you create a new project that points to this version of dioxus and try to serve it with the old version of the CLI, no assets are copied |
I don't see a way around breaking enum deserialization since we need to pass an identifier to preserve files somehow. |
Adds the
FolderAssetOptions::new().into_preserved()
method for a preserved unoptimized folder. This is planned to be a temporary workaround until we can make breaking changes in 0.7. Below is the original plan for 0.7:Original Plan:
Adds a
optimize_files
option forFolderAsset
e.g.If the flag is set, the file will go under minor processing. The flag defaults to
true
to maintain current behavior.