Skip to content

Commit fcea9ce

Browse files
authored
(feat) add sveltekit:reload (#1431)
sveltejs/kit#4545 Refactoring new transformation along the way, removing unnecessary code
1 parent 28fe541 commit fcea9ce

File tree

9 files changed

+31
-20
lines changed

9 files changed

+31
-20
lines changed

packages/language-server/src/plugins/html/dataProvider.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ const addAttributes: Record<string, IAttributeData[]> = {
288288
description:
289289
"SvelteKit-specific attribute. Will cause SvelteKit to run the page's load function as soon as the user hovers over the link (on a desktop) or touches it (on mobile), rather than waiting for the click event to trigger navigation.",
290290
valueSet: 'v'
291+
},
292+
{
293+
name: 'sveltekit:reload',
294+
description:
295+
'SvelteKit-specific attribute. Will cause SvelteKit to do a normal browser navigation which results in a full page reload.',
296+
valueSet: 'v'
291297
}
292298
],
293299
details: [

packages/svelte2tsx/src/htmlxtojsx/nodes/attribute.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ export function handleAttribute(
6060
//if we are on an "element" we are case insensitive, lowercase to match our JSX
6161
if (parent.type == 'Element') {
6262
const sapperLinkActions = ['sapper:prefetch', 'sapper:noscroll'];
63-
const sveltekitLinkActions = ['sveltekit:prefetch', 'sveltekit:noscroll'];
63+
const sveltekitLinkActions = [
64+
'sveltekit:prefetch',
65+
'sveltekit:noscroll',
66+
'sveltekit:reload'
67+
];
6468
// skip Attribute shorthand, that is handled below
6569
if (
6670
(attr.value !== true &&

packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ const numberOnlyAttributes = new Set([
2929
'results',
3030
'volume'
3131
]);
32-
const sapperLinkActions = ['sapper:prefetch', 'sapper:noscroll'];
33-
const sveltekitLinkActions = ['sveltekit:prefetch', 'sveltekit:noscroll'];
3432

3533
/**
3634
* Handle various kinds of attributes and make them conform to being valid in context of a object definition
@@ -109,13 +107,7 @@ export function handleAttribute(
109107

110108
const attributeName: TransformationArray = [];
111109

112-
if (sapperLinkActions.includes(attr.name) || sveltekitLinkActions.includes(attr.name)) {
113-
//strip ":" from out attribute name and uppercase the next letter to convert to jsx attribute
114-
const parts = attr.name.split(':');
115-
const name = parts[0] + parts[1][0].toUpperCase() + parts[1].substring(1);
116-
str.overwrite(attr.start, attr.start + attr.name.length, name);
117-
attributeName.push([attr.start, attr.start + attr.name.length]);
118-
} else if (attributeValueIsOfType(attr.value, 'AttributeShorthand')) {
110+
if (attributeValueIsOfType(attr.value, 'AttributeShorthand')) {
119111
// For the attribute shorthand, the name will be the mapped part
120112
addAttribute([[attr.value[0].start, attr.value[0].end]]);
121113
return;

packages/svelte2tsx/svelte-jsx.d.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,16 @@ declare namespace svelteHTML {
9898
// eslint-disable-next-line @typescript-eslint/no-empty-interface
9999
interface SvelteWindowProps extends svelte.JSX.SvelteWindowProps {}
100100

101-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
102-
interface SapperAnchorProps extends svelte.JSX.SapperAnchorProps {}
103-
104-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
105-
interface SvelteKitAnchorProps extends svelte.JSX.SvelteKitAnchorProps {}
101+
interface SapperAnchorProps {
102+
"sapper:noscroll"?: true | undefined | null;
103+
"sapper:prefetch"?: true | undefined | null;
104+
}
105+
106+
interface SvelteKitAnchorProps {
107+
"sveltekit:noscroll"?: true | undefined | null;
108+
"sveltekit:prefetch"?: true | undefined | null;
109+
"sveltekit:reload"?: true | undefined | null;
110+
}
106111

107112
// eslint-disable-next-line @typescript-eslint/no-empty-interface
108113
interface SvelteMediaTimeRange extends svelte.JSX.SvelteMediaTimeRange {}
@@ -1230,6 +1235,7 @@ declare namespace svelte.JSX {
12301235
// transformed from sveltekit:noscroll so it should be camel case
12311236
sveltekitNoscroll?: true | undefined | null;
12321237
sveltekitPrefetch?: true | undefined | null;
1238+
sveltekitReload?: true | undefined | null;
12331239
}
12341240

12351241
interface SvelteMediaTimeRange {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ svelteHTML.createElement("a", {sapperNoscroll:true,}); }
1+
{ svelteHTML.createElement("a", {"sapper:noscroll":true,}); }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ svelteHTML.createElement("a", {sapperPrefetch:true,}); }
1+
{ svelteHTML.createElement("a", {"sapper:prefetch":true,}); }
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<><a sveltekitNoscroll></a>
2-
<a sveltekitPrefetch></a></>
2+
<a sveltekitPrefetch></a>
3+
<a sveltekitReload></a></>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
{ svelteHTML.createElement("a", {sveltekitNoscroll:true,}); }
2-
{ svelteHTML.createElement("a", {sveltekitPrefetch:true,}); }
1+
{ svelteHTML.createElement("a", {"sveltekit:noscroll":true,}); }
2+
{ svelteHTML.createElement("a", {"sveltekit:prefetch":true,}); }
3+
{ svelteHTML.createElement("a", {"sveltekit:reload":true,}); }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<a sveltekit:noscroll></a>
22
<a sveltekit:prefetch></a>
3+
<a sveltekit:reload></a>

0 commit comments

Comments
 (0)