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

Add Svelte 5 runes support #59

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Add Svelte 5 runes support #59

wants to merge 12 commits into from

Conversation

rtrampox
Copy link

Refactor code in favor of new svelte 5 runes syntax.

  • Upgrade svelte and its dependencies to the latest version.
  • Add CropperProps type that describes all the component props.
  • Update $ syntax to $effect() and $state() for runes mode support.

Copy link

socket-security bot commented Dec 14, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@esbuild/[email protected] None 0 11.2 MB evanw
npm/@esbuild/[email protected] None 0 11.9 MB evanw
npm/@esbuild/[email protected] None 0 10.6 MB evanw
npm/@esbuild/[email protected] None 0 11.9 MB evanw
npm/@esbuild/[email protected] None 0 9.75 MB evanw
npm/@esbuild/[email protected] None 0 10.4 MB evanw
npm/@esbuild/[email protected] None 0 9.5 MB evanw
npm/@esbuild/[email protected] None 0 10.2 MB evanw
npm/@esbuild/[email protected] None 0 9.63 MB evanw
npm/@esbuild/[email protected] None 0 9.57 MB evanw
npm/@esbuild/[email protected] None 0 9.59 MB evanw
npm/@esbuild/[email protected] None 0 9.77 MB evanw
npm/@esbuild/[email protected] None 0 10.9 MB evanw
npm/@esbuild/[email protected] None 0 9.83 MB evanw
npm/@esbuild/[email protected] None 0 9.44 MB evanw
npm/@esbuild/[email protected] None 0 10.7 MB evanw
npm/@esbuild/[email protected] None 0 10.2 MB evanw
npm/@esbuild/[email protected] None 0 10.1 MB evanw
npm/@esbuild/[email protected] None 0 9.57 MB evanw
npm/@esbuild/[email protected] None 0 10.2 MB evanw
npm/@esbuild/[email protected] None 0 10.2 MB evanw
npm/@esbuild/[email protected] None 0 9.57 MB evanw
npm/@esbuild/[email protected] None 0 9.85 MB evanw
npm/@esbuild/[email protected] None 0 10.4 MB evanw
npm/@jridgewell/[email protected] None 0 0 B
npm/@jridgewell/[email protected] None 0 17.9 kB jridgewell
npm/@jridgewell/[email protected] None 0 113 kB jridgewell
npm/@jridgewell/[email protected] None 0 169 kB jridgewell
npm/@rollup/[email protected] None 0 1.61 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.23 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.21 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.37 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.13 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.46 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.24 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.24 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.22 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.11 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.56 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.76 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.26 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 3.83 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.5 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.48 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.74 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 2.58 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/[email protected] None 0 3.29 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@sveltejs/[email protected] None +1 849 kB conduitry, dominik_g, rich_harris, ...1 more
npm/@sveltejs/[email protected] None 0 29.1 kB svelte-admin
npm/@sveltejs/[email protected] Transitive: environment +1 68.7 kB svelte-admin
npm/@sveltejs/[email protected] None 0 126 kB conduitry, dominik_g, rich_harris, ...1 more
npm/@types/[email protected] None 0 25.8 kB types
npm/[email protected] None 0 532 kB tyrealhu
npm/[email protected] None 0 547 kB marijn
npm/[email protected] None 0 176 kB ljharb
npm/[email protected] None 0 111 kB ljharb
npm/[email protected] None 0 149 kB paulmillr
npm/[email protected] None 0 31.8 kB rich_harris
npm/[email protected] environment, filesystem, network, shell 0 134 kB evanw
npm/[email protected] None 0 3.94 kB benmccann
npm/[email protected] None 0 48.7 kB rich_harris
npm/[email protected] None 0 3.95 kB rich_harris
npm/[email protected] None 0 467 kB alangpierce, antfu, mourner, ...1 more
npm/[email protected] None 0 6.72 kB styfle
npm/[email protected] environment 0 1.5 MB dummdidumm
npm/[email protected] None 0 7.83 MB prettier-bot
npm/[email protected] filesystem 0 32.2 kB paulmillr
npm/[email protected] None 0 2.61 MB eventualbuddha, lukastaegert, rich_harris, ...2 more
npm/[email protected] None 0 21.8 kB lukeed
npm/[email protected] None 0 2.47 MB conduitry, rich_harris, svelte-admin
npm/[email protected] None 0 758 kB svelte-language-tools-deploy
npm/[email protected] Transitive: environment, filesystem +3 3.16 MB antfu, patak, soda, ...2 more
npm/[email protected] None 0 20.8 kB bluwy
npm/[email protected] None 0 12.3 kB rich_harris

🚮 Removed packages: npm/@jridgewell/[email protected], npm/@jridgewell/[email protected], npm/@jridgewell/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@rollup/[email protected], npm/@sveltejs/[email protected], npm/@sveltejs/[email protected], npm/@sveltejs/[email protected], npm/@sveltejs/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected]

View full report↗︎

@rtrampox
Copy link
Author

Added export from types file, as it can be useful when working around the package.

@ValentinH
Copy link
Owner

Would using the new syntax break the backward compatibility for people using the previous Svelte versions?

@rtrampox
Copy link
Author

rtrampox commented Dec 23, 2024

Would using the new syntax break the backward compatibility for people using the previous Svelte versions?

From what I found, it seems like yes. Maybe you can publish as an next version of the package?

With the latest version of the package, svelte shows a lot of warnings on the console that some of the reactive statements won't work because they are not supported anymore by Svelte 5.

@ValentinH
Copy link
Owner

Would using the new syntax break the backward compatibility for people using the previous Svelte versions?

From what I found, it seems like yes. Maybe you can publish as an next version of the package?

With the latest version of the package, svelte shows a lot of warnings on the console that some of the reactive statements won't work because they are not supported anymore by Svelte 5.

Oh ok, I didn't know that. Then it totally makes sense to publish this update as a new major version.


// when zoom changes, we recompute the cropped area
$: zoom && emitCropData()
let lastZoom = $state(zoom);
Copy link
Owner

Choose a reason for hiding this comment

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

We should not need to track the last zoom value ourselves, Svelte should do it automatically as long as we access zoom in the effect.

Copy link
Author

Choose a reason for hiding this comment

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

This one can be removed safely without causing loops. Just added it for testing and forgot to remove

computeSizes()
emitCropData()
}
let lastAspect = $state(aspect);
Copy link
Owner

Choose a reason for hiding this comment

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

Same here, this state should not be needed.

Copy link
Author

Choose a reason for hiding this comment

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

The lastAspect is required here, when checking for just the aspect variable, it enters an infinite loop.

src/lib/Cropper.svelte Show resolved Hide resolved
Copy link

socket-security bot commented Dec 24, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Obfuscated code npm/[email protected] ⚠︎

View full report↗︎

Next steps

What is obfuscated code?

Obfuscated files are intentionally packed to hide their behavior. This could be a sign of malware.

Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

src/lib/Cropper.svelte Outdated Show resolved Hide resolved
Comment on lines 257 to 265
// this variable is required to prevent the effect into entering an infinite loop (https://github.com/ValentinH/svelte-easy-crop/pull/59#discussion_r1896254867)
let lastAspect = $state(aspect)
$effect(() => {
if (aspect !== lastAspect) {
lastAspect = aspect
computeSizes()
emitCropData()
}
})
Copy link
Owner

Choose a reason for hiding this comment

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

When do you reach the infinite loop? When changing the aspect prop? With the additional state, I expect this effect to run twice for every time the aspect prop changes. 🤔

Copy link
Author

Choose a reason for hiding this comment

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

image
This is what happens with only

$effect(() => {
    if (aspect) {
      lastAspect = aspect
      computeSizes()
      emitCropData()
    }
  })

This is the loop warning:
image

Copy link
Owner

Choose a reason for hiding this comment

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

I think this is because of the lastAspect assignment. Why do we need it? This variable wasn't here before.

Copy link
Author

Choose a reason for hiding this comment

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

image

$effect(() => {
    if (aspect) {
      computeSizes()
      emitCropData()
    }
  })

same thing happens without it. Will try to find out why this is happening.

I think this is because of the lastAspect assignment. Why do we need it? This variable wasn't here before.

I added it there to prevent the loop, it was the only fix I found

Copy link
Author

Choose a reason for hiding this comment

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

Actually, do you know the use of this effect right here? It seems that the component works as it should without it.

Copy link
Author

Choose a reason for hiding this comment

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

After testing for some while, it seems that this effect has no use, even when the aspect is dynamically updated.

src/lib/Cropper.svelte Outdated Show resolved Hide resolved
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.

2 participants