Skip to content

Commit 7e9594b

Browse files
authored
Merge pull request #7963 from QwikDev/v2-fix-repl-links
fix(repl): restore v2 compression dictionary
2 parents 4669425 + e7b3a46 commit 7e9594b

File tree

2 files changed

+94
-10
lines changed

2 files changed

+94
-10
lines changed

packages/docs/src/repl/ui/repl-share-url.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export const strToFiles = (str: string) => {
8585
// You can add new entries to the beginning though.
8686
export const dictionary = strToU8(
8787
filesToStr([
88+
{
89+
path: '/app.tsx',
90+
code: `import { component$ } from '@qwik.dev/core';\n\nexport default component$(() => {\n return (\n <div>\n <h1>Hello from Qwik!</h1>\n </div>\n );\n`,
91+
},
8892
{
8993
path: '',
9094
// Extra words to help with compression
@@ -98,7 +102,7 @@ export const dictionary = strToU8(
98102
// You need to add a new section like this before this section instead
99103
code: `<div> </div> </button> props: class return ( story component$( store string state export const span type href={ page strong count useSignal< useStore< qwik import { } from searchInput console.log( searchResults builder useTask$( stories style={ news export default data </article> track onClick$= new nav map link debounced controller user useStyles$( useStylesScoped$( url title timeoutId time_ago second response Date.now() minute main item interface hour disabled aria any State update transform the target suggestion setTimeout selectedValue rotate render people number list label https:// header deg debouncedGetPeople debounce component comments_count comments clock background await new Promise args SuggestionsListComponent IStory IState IComment GrandChild Clock Child AutoComplete 360 yellow with view useVisibleTask$( true tmrId timer then swapi styles signal section search results resolve rel prev points parsedResponse null noreferrer name more length json job items isServer index github getPeople function fetch example domain dev delay css container com click clearTimeout async api _blank Star Wars API This The StoryPreview Stories ReturnType Qwik App Page Nav HackerNewsCSS AbortController server$( routeAction$( routeLoader$( useContent( useDocumentHead( useLocation( useNavigate( validator$( zod$( noSerialize( </Slot> useComputed$( useOnDocument( useOnWindow( useResource$( useContext( useContextProvider( createContextId<`,
100104
},
101-
// The default hello world app + supporting files
105+
// The old default hello world app + supporting files
102106
{
103107
path: '/app.tsx',
104108
code: `import { component$ } from '@builder.io/qwik';\n\nexport default component$(() => {\n return <p>Hello Qwik</p>;\n});\n`,
@@ -168,6 +172,7 @@ export function parseCompressedFiles(filesBase64: string) {
168172
const filesBuf = inflateSync(compressedUint8Array, { dictionary });
169173
filesStr = strFromU8(filesBuf);
170174
} catch (error) {
175+
console.error('Could not decode URL, falling back to uncompressed');
171176
// Treat string as not compressed
172177
filesStr = decodeURIComponent(encoded);
173178
}

packages/docs/src/repl/ui/repl-share-url.unit.ts

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { assert, test } from 'vitest';
1+
import { strFromU8 } from 'fflate';
2+
import { assert, expect, test } from 'vitest';
23
import {
3-
filesToStr,
4-
strToFiles,
5-
createPlaygroundShareUrl,
64
compressFiles,
7-
parseCompressedFiles,
5+
createPlaygroundShareUrl,
86
dictionary,
7+
filesToStr,
8+
parseCompressedFiles,
9+
parsePlaygroundShareUrl,
10+
strToFiles,
911
} from './repl-share-url';
10-
import { strFromU8 } from 'fflate';
1112

1213
const data = {
1314
version: '1.2.3',
@@ -64,8 +65,86 @@ test('createPlaygroundShareUrl 2', () => {
6465
});
6566

6667
test('dictionary is unchanged', () => {
67-
assert.equal(
68-
strFromU8(dictionary),
69-
"0||1448|<div> </div> </button> props: class return ( story component$( store string state export const span type href={ page strong count useSignal< useStore< qwik import { } from searchInput console.log( searchResults builder useTask$( stories style={ news export default data </article> track onClick$= new nav map link debounced controller user useStyles$( useStylesScoped$( url title timeoutId time_ago second response Date.now() minute main item interface hour disabled aria any State update transform the target suggestion setTimeout selectedValue rotate render people number list label https:// header deg debouncedGetPeople debounce component comments_count comments clock background await new Promise args SuggestionsListComponent IStory IState IComment GrandChild Clock Child AutoComplete 360 yellow with view useVisibleTask$( true tmrId timer then swapi styles signal section search results resolve rel prev points parsedResponse null noreferrer name more length json job items isServer index github getPeople function fetch example domain dev delay css container com click clearTimeout async api _blank Star Wars API This The StoryPreview Stories ReturnType Qwik App Page Nav HackerNewsCSS AbortController server$( routeAction$( routeLoader$( useContent( useDocumentHead( useLocation( useNavigate( validator$( zod$( noSerialize( </Slot> useComputed$( useOnDocument( useOnWindow( useResource$( useContext( useContextProvider( createContextId<|8|/app.tsx|114|import { component$ } from '@builder.io/qwik';\n\nexport default component$(() => {\n return <p>Hello Qwik</p>;\n});\n|17|/entry.server.tsx|201|import { renderToString, type RenderOptions } from '@builder.io/qwik/server';\nimport { Root } from './root';\n\nexport default function (opts: RenderOptions) {\n return renderToString(<Root />, opts);\n}\n|9|/root.tsx|192|import App from './app';\n\nexport const Root = () => {\n return (\n <>\n <head>\n <title>Hello Qwik</title>\n </head>\n <body>\n <App />\n </body>\n </>\n );\n};\n"
68+
const dictionaryAsString = strFromU8(dictionary);
69+
// !!! THIS DICTIONARY MUST NEVER CHANGE - ONLY ALLOW PREPENDING !!!
70+
expect(dictionaryAsString).toMatchInlineSnapshot(`
71+
"8|/app.tsx|149|import { component$ } from '@qwik.dev/core';
72+
73+
export default component$(() => {
74+
return (
75+
<div>
76+
<h1>Hello from Qwik!</h1>
77+
</div>
78+
);
79+
|0||1448|<div> </div> </button> props: class return ( story component$( store string state export const span type href={ page strong count useSignal< useStore< qwik import { } from searchInput console.log( searchResults builder useTask$( stories style={ news export default data </article> track onClick$= new nav map link debounced controller user useStyles$( useStylesScoped$( url title timeoutId time_ago second response Date.now() minute main item interface hour disabled aria any State update transform the target suggestion setTimeout selectedValue rotate render people number list label https:// header deg debouncedGetPeople debounce component comments_count comments clock background await new Promise args SuggestionsListComponent IStory IState IComment GrandChild Clock Child AutoComplete 360 yellow with view useVisibleTask$( true tmrId timer then swapi styles signal section search results resolve rel prev points parsedResponse null noreferrer name more length json job items isServer index github getPeople function fetch example domain dev delay css container com click clearTimeout async api _blank Star Wars API This The StoryPreview Stories ReturnType Qwik App Page Nav HackerNewsCSS AbortController server$( routeAction$( routeLoader$( useContent( useDocumentHead( useLocation( useNavigate( validator$( zod$( noSerialize( </Slot> useComputed$( useOnDocument( useOnWindow( useResource$( useContext( useContextProvider( createContextId<|8|/app.tsx|114|import { component$ } from '@builder.io/qwik';
80+
81+
export default component$(() => {
82+
return <p>Hello Qwik</p>;
83+
});
84+
|17|/entry.server.tsx|201|import { renderToString, type RenderOptions } from '@builder.io/qwik/server';
85+
import { Root } from './root';
86+
87+
export default function (opts: RenderOptions) {
88+
return renderToString(<Root />, opts);
89+
}
90+
|9|/root.tsx|192|import App from './app';
91+
92+
export const Root = () => {
93+
return (
94+
<>
95+
<head>
96+
<title>Hello Qwik</title>
97+
</head>
98+
<body>
99+
<App />
100+
</body>
101+
</>
102+
);
103+
};
104+
"
105+
`);
106+
});
107+
108+
test('previous URLs still work', () => {
109+
expect(parsePlaygroundShareUrl('f=G000o4mG5EQDAA')).toHaveProperty(
110+
'files',
111+
// DO NOT UPDATE THIS TEST - all these URLs must work forever
112+
expect.arrayContaining([
113+
expect.objectContaining({
114+
path: '/app.tsx',
115+
code: "import { component$ } from '@builder.io/qwik';\n\nexport default component$(() => {\n return <p>Hello Qwik</p>;\n});\n",
116+
}),
117+
])
118+
);
119+
expect(
120+
parsePlaygroundShareUrl(
121+
'f=Q0o0xgaW2BKNDrDkqNCB15QUpyFIgKTl51uBeGA%2BKO%2BBIwaW0W1A6SI%2FDWQzyKm1wKBDVwyU0lAqUNJRqE4GFc3AqLNSCnENDlGq1QTpAGJ43a5RDa6oa0FOgBsDbxkAXQIMCqAWMIktXqqBSvRgNoNMRg7C0XQ%2FJNM9AA'
122+
)
123+
).toHaveProperty(
124+
'files',
125+
// DO NOT UPDATE THIS TEST - all these URLs must work forever
126+
expect.arrayContaining([
127+
expect.objectContaining({
128+
path: '/app.tsx',
129+
code: `import { component$, jsx, useTask$ } from '@builder.io/qwik';
130+
131+
export default component$(() => {
132+
const foo:{
133+
contents: ReturnType<typeof jsx>
134+
} = {
135+
contents: jsx("p", {children:"TEST"})
136+
}
137+
useTask$(({track}) =>{
138+
console.log(foo);
139+
});
140+
return (
141+
<>
142+
{foo.contents}
143+
</>
144+
);
145+
});
146+
`,
147+
}),
148+
])
70149
);
71150
});

0 commit comments

Comments
 (0)