Skip to content

fix: ensure $effect.root is ignored on the server #12332

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

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

dummdidumm
Copy link
Member

Alternate PR to #12331 - choose one.

Ignore the contents of the effect root, just return a noop where necessary

fixes #12322

Svelte 5 rewrite

Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (main).

If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is svelte-4 and not main.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Ignore the contents of the effect root, just return a noop where necessary

fixes #12322
Copy link

changeset-bot bot commented Jul 7, 2024

🦋 Changeset detected

Latest commit: ed054fb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined towards this fix over the other one, but will wait to see if others feel strongly

@dummdidumm
Copy link
Member Author

I'm mostly indifferent. I think it doesn't matter too much either way, because for this to have any practical consequences you would have to do some kind of eager side effect inside the effect root (like logging, which you want to do on the server, too), or jump through hoops to create a variable outside the effect root, eagerly assign to it from inside, then return that variable synchronously, and do something with the result (like using it as an attribute value).

I think it mainly comes down to whether or not it's easily possible to move the stuff you want to run in SSR outside of the effect root, so it always executes.

@abdel-17
Copy link

abdel-17 commented Jul 8, 2024

I think a weird edge case with running $effect.root only on the server is manual cleanup.

Say I have some utility that creates effects under the hood. If I want it to be global, I have to initialize it inside of an effect root.

let foo: Foo;

const cleanup = effect.root(() => {
  foo = new Foo();
});

export { foo, cleanup };

@dummdidumm
Copy link
Member Author

We decided to go with this variant for now, for the following reasons:

  • the other $effect runes are also ignored on the server
  • it's an edge case (and should remain one) to use this rune at all
  • it's an even bigger edge case to use these on the server in a way that they are used eagerly while rendering

@dummdidumm dummdidumm merged commit 243c4b7 into main Jul 8, 2024
9 checks passed
@dummdidumm dummdidumm deleted the effect-root-alternate-fix branch July 8, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Svelte 5: Incorrect Server Output for $effect.root
3 participants