Skip to content

Commit

Permalink
fix(inspector): use runes and force runes mode (#1004)
Browse files Browse the repository at this point in the history
* fix(inspector) use runes and force runes mode to avoid issues in client apps that set runes mode globally

* Update .changeset/cold-hats-leave.md

Co-authored-by: Bjorn Lu <[email protected]>

* fix: disable prefer-const rule for svelte files as it does not handle deriveds well

---------

Co-authored-by: Bjorn Lu <[email protected]>
  • Loading branch information
dominikg and bluwy authored Oct 23, 2024
1 parent 52e4a4f commit dc6e808
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-hats-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte-inspector': patch
---

fix(inspector): migrate client component to runes and force runes mode
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export default [
},

rules: {
'n/no-missing-import': 'off' // n doesn't know some vite specifics or monorepo imports.
'n/no-missing-import': 'off', // n doesn't know some vite specifics or monorepo imports.
'prefer-const': 'off' // this turns let foo = $derived into a const otherwise
}
},
{
Expand Down
22 changes: 13 additions & 9 deletions packages/vite-plugin-svelte-inspector/src/runtime/Inspector.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<svelte:options runes={true} />

<script>
// do not use TS here so that this component works in non-ts projects too
import { onMount } from 'svelte';
Expand All @@ -8,8 +10,8 @@
const nav_keys = Object.values(options.navKeys).map((k) => k?.toLowerCase());
const open_key = options.openKey?.toLowerCase();
let enabled = false;
let has_opened = false;
let enabled = $state(false);
let has_opened = $state(false);
const icon = `data:image/svg+xml;base64,${btoa(
`
Expand All @@ -24,17 +26,19 @@
)}`;
// location of code in file
let file_loc;
let file_loc = $state();
// cursor pos and width for file_loc overlay positioning
let x, y, w;
let x = $state(),
y = $state(),
w = $state();
let active_el;
let active_el = $state();
let hold_start_ts;
let hold_start_ts = $state();
$: show_toggle =
// eslint-disable-next-line svelte/valid-compile
options.showToggleButton === 'always' || (options.showToggleButton === 'active' && enabled);
let show_toggle = $derived(
options.showToggleButton === 'always' || (options.showToggleButton === 'active' && enabled)
);
function mousemove(e) {
x = e.x;
Expand Down

0 comments on commit dc6e808

Please sign in to comment.