Repository navigation
fix: use_memo/use_effect see in-place changes to observable lists; Icons[name]; use_dialog rejects non-dialogs - #7114
Open
FeodorFitsner wants to merge 2 commits into
Open
FeodorFitsner wants to merge 2 commits into
FeodorFitsner wants to merge 2 commits into
Conversation
… dicts; Icons[name]; use_dialog rejects non-dialogs - use_memo() and use_effect() record observable list/dict dependencies with a per-field change counter, so state.items.append(x) recomputes the memo and re-runs the effect. Different collections still compare by items. - Icons, CupertinoIcons and LucideIcons support ["NAME"] lookup and "NAME" in Icons; stubs (and their templates) type it as IconData. - use_dialog() raises a TypeError for a component call or a non-dialog control instead of silently never opening it. - Cookbook: building a dialog in a helper function. - typos: skip the generated material and Cupertino icon stubs, which carry Flutter's spelling, like the Lucide stub already is.
Deploying flet-website-v2 with
|
| Latest commit: |
a859b07
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b470b6ba.flet-website-v2.pages.dev |
| Branch Preview URL: | https://fix-declarative-api-edges.flet-website-v2.pages.dev |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Three edges of the declarative API that came up while building a reference app for the Flet Studio agent. Each one cost a debugging loop because it fails silently.
use_memo/use_effectand in-place changesuse_memo(fn, [state.items])never recomputed afterstate.items.append(x), anduse_effectwith the same dependency never re-ran. Dependencies are compared withis/==, and an observable list is the same object after an in-place change, so it always compared equal to itself.Observables now keep a change counter per field (
_notify(field)bumps it;notify()bumps a shared one).use_memoanduse_effectrecord an observable list or dict dependency together with its field's counter (capture_dependencies()), so:state.items = [1, 2]over an equal list doesn't recompute);Whole
Observableobjects passed as dependencies keep comparing by identity. Making them version-aware would makeuse_effect(state.load, [state])loop forever.@ft.memocomponents already subscribe to observable props, so they needed no change.Icons["NAME"]Material, Cupertino and Lucide icons are proxies with
__getattr__, soft.Icons["HOME"], the enum-style lookup, raisedTypeError. The proxies now have__getitem__(aKeyErrorfor an unknown name) and__contains__."HOME" in ft.Iconschecks a name, andft.Icons.HOME in ft.Iconsstill works. The stubs and their templates declare both on a metaclass, so mypy and pyright typeft.Icons["HOME"]asIconData.use_dialog()and non-dialogsA dialog returned from an
@ft.componentfunction is aComponent, not aDialogControl, souse_dialog()added it to the overlay and it never opened, with no error. It now raises aTypeErrorthat names the component and says to build the dialog inline or in a plain function. Any other non-dialog control gets aTypeErrortoo. The declarative dialogs cookbook page gains a short "Building a dialog in a helper function" section.Also
The
typospre-commit hook now skips the generated material and Cupertino icon stubs, which carry Flutter's spelling (FLOURESCENT,THREED_ROTATION), as it already did for the Lucide stub. Editing the material stub tripped it.Test code
Before: clicking "Append 7" twice leaves
total=15 effect_runs=1;ft.Icons["ADD_SHOPPING_CART"]raises; "Wrapped dialog" does nothing. After:total=29 effect_runs=3, the icon renders, and the error explains the dialog. I checked this in web server mode in headless Chrome.Tests
tests/test_hook_dependencies.py(new): memo and effect after append, item replace/pop, nested list, dict,notify(); no recompute for other fields or a new equal list.tests/test_icons.py: lookup and membership by name and by value.tests/test_use_dialog.py:TypeErrorfor a component and for a non-dialog control.main. Full suite: 570 passed, 9 skipped.Summary by Sourcery
Make declarative state dependencies observe in-place collection changes, expand icon lookup, and fail clearly for unsupported dialog values.
New Features:
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: