Skip to content
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

Invalidate Composable on resource change #63

Open
sellmair opened this issue Jan 17, 2025 · 5 comments
Open

Invalidate Composable on resource change #63

sellmair opened this issue Jan 17, 2025 · 5 comments

Comments

@sellmair
Copy link
Member

e.g. changing a string in a strings.xml should invalidate all composables that relied on the resource

@sellmair
Copy link
Member Author

I'll start experimenting with this now 🤔

@sellmair
Copy link
Member Author

sellmair commented Jan 22, 2025

First attempt:
Certain calls (e.g. like calling into the ResourceItem constructor) could resolve the resource when building their associated code hash. This would automatically change the invalidation key of every scope depending on the resource item.

Issue 1 with this approach:
Calling Res.string.product might not happen in the scope which actually resolves the value using e.g. stringResource

Issue 2:
Even though the code hash changes, it would still require some invalidation request, because just changing the value of a stringResource might not lead to actual code change.

@sellmair
Copy link
Member Author

Next attempt:
Allow for dynamic hooks into the reload machinery (e.g. a hook called when the reload was performed).
This hook could e.g. clear the 'stringItemsCache' and invalidate resource loading Composables.

The issue here is that I am unsure about how to keep the granularity fine enough to be enjoyable.

@sellmair
Copy link
Member Author

sellmair commented Jan 22, 2025

Issue: Re-initialization of the lazy StringResource instances referenced by the Singleton CommonMainString0

(Decompiled)

final class CommonMainString0 {
    @NotNull
    public static final CommonMainString0 INSTANCE = new CommonMainString0();
    @NotNull
    private static final Lazy company$delegate = LazyKt.lazy(CommonMainString0::company_delegate$lambda$0);
    @NotNull
    private static final Lazy product$delegate = LazyKt.lazy(CommonMainString0::product_delegate$lambda$1);

    private CommonMainString0() {
    }

    @NotNull
    public final StringResource getCompany() {
        Lazy var1 = company$delegate;
        return (StringResource)var1.getValue();
    }

    @NotNull
    public final StringResource getProduct() {
        Lazy var1 = product$delegate;
        return (StringResource)var1.getValue();
    }

    private static final StringResource company_delegate$lambda$0() {
        return String0_commonMainKt.access$init_company();
    }

    private static final StringResource product_delegate$lambda$1() {
        return String0_commonMainKt.access$init_product();
    }
}

If the offsets change, the StringResource objects have to be re-initialized.

@sellmair
Copy link
Member Author

Two options come to mind:

  1. Provide hooks into hot reload and let some code handle re-initialization like
    invokeOnHotReload { }

  2. Provide a way to force re-initialization of objects by only providng an annotation or even known FQN or package names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant