-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
docs: clarify example on dynamic dependency tracking #13767
base: main
Are you sure you want to change the base?
docs: clarify example on dynamic dependency tracking #13767
Conversation
|
21c7c85
to
01197d6
Compare
Maybe we could add a potential workaround, to further clarify the behaviour? Example: Escape Hatch: Forcing Effect Re-Runs on Every State ChangeIf you really need to ensure that the effect always runs when either let a = $state(false);
let b = $state(false);
$effect(() => {
// Explicitly reference `a` and `b` so this effect re-runs whenever they change
a;
b;
// This will run on every change to either `a` or `b`
console.log('running');
if (a || b) {
console.log('inside if block');
}
}); This approach establishes direct dependencies on both
|
01197d6
to
36116fc
Compare
We could do something like that. Though, my original scope for this PR was to simply expound on the I'll wait on the Svelte team to chime in on how to best proceed here. |
Hello there! Just gonna bump this PR. I'd like to know if there are any concerns with the way I worded the clarification (and possibly improvements if necessary). Thanks again! |
Description
This PR clarifies the explanation behind the short-circuiting
a || b
example used in the$effect
guide. I personally felt like the original explanation was too short and too handwavy over the fascinating implications of dynamic dependency tracking. So, I expanded the explanation to cover both cases (i.e., whena
isfalse
and whena
istrue
).Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint