-
-
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
page.params from $app/state not a rune server-side #14954
Comments
This isn't so much related to So yes, your solution to not use |
thx for the clarification @dummdidumm ! I was under the impression that any application state managed previously through svelte stores could be migrated to While the uppercase example is very simplistic, users might want to use the power of runes to combine route params or data with other $states... import {page} from '$app/state';
export const appState = new (class AppState{
#awesomeDevs = $state(['Rich', 'Simon']);
#isAwesomeDev = $derived(this.#awesomeDevs.includes(page.params.name));
get isAwesomeDev() {
return this.#isAwesomeDev;
}
set awesomeDevs(devs: string[]) {
this.#awesomeDevs = devs;
}
})(); I am not sure how valid this kind of 'usage' is to be fair... |
Transferred this to the <script>
let a = $state(1);
let b = $derived(a * 2);
</script>
<h1>{a} * 2 = {b}</h1> ...becomes this: export default function App($$payload) {
let a = 1;
- let b = a * 2;
+ let b = () => a * 2;
- $$payload.out += `<h1>${$.escape(a)} * 2 = ${$.escape(b)}</h1>`;
+ $$payload.out += `<h1>${$.escape(a)} * 2 = ${$.escape(b())}</h1>`;
} Meanwhile class deriveds, like the one above, would change thusly (i.e. just removing the // input
class Routing {
nameUpper = $derived(page.params.name?.toUpperCase())
} // output
class Routing {
- #nameUpper = $.once(() => page.params.name?.toUpperCase());
+ #nameUpper = () => page.params.name?.toUpperCase();
get nameUpper() {
return this.#nameUpper();
}
} Two obvious downsides:
Maybe a compromise that solves the case at hand without causing extra work in the majority of cases would be to distinguish between deriveds that belong to a component instance (which shouldn't change during rendering, unless you're doing inadvisable things) and those that don't. |
Describe the bug
I don't think this is a bug, but would like to open the discussion through this issue.
We now have the possibility to use the
page
object from$app/state
instead of the store from$app/stores
, which is awesome !Something that could be confusing however is that the
page
object exposes runes only in client mode, and not in server mode.Which means that if a user writes the following code:
This will work perfectly fine client-side, but will not work for pre-rendered routes !
You can check the reproduction link to see it.
Obviously, a simple fix is updating the above code to the following:
So there is no bug, just a slight confusion... Should users avoid using
$derived
with the page info ? Should they check if running in the browser to use$derived
or simple getters ?Reproduction
https://github.com/quentinderoubaix/showcase-app-state-behavior
Logs
No response
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: