Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/docs/src/repl/ui/repl-share-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export const strToFiles = (str: string) => {
// You can add new entries to the beginning though.
export const dictionary = strToU8(
filesToStr([
{
path: '/app.tsx',
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`,
},
{
path: '',
// Extra words to help with compression
Expand All @@ -98,7 +102,7 @@ export const dictionary = strToU8(
// You need to add a new section like this before this section instead
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<`,
},
// The default hello world app + supporting files
// The old default hello world app + supporting files
{
path: '/app.tsx',
code: `import { component$ } from '@builder.io/qwik';\n\nexport default component$(() => {\n return <p>Hello Qwik</p>;\n});\n`,
Expand Down Expand Up @@ -168,6 +172,7 @@ export function parseCompressedFiles(filesBase64: string) {
const filesBuf = inflateSync(compressedUint8Array, { dictionary });
filesStr = strFromU8(filesBuf);
} catch (error) {
console.error('Could not decode URL, falling back to uncompressed');
// Treat string as not compressed
filesStr = decodeURIComponent(encoded);
}
Expand Down
97 changes: 88 additions & 9 deletions packages/docs/src/repl/ui/repl-share-url.unit.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { assert, test } from 'vitest';
import { strFromU8 } from 'fflate';
import { assert, expect, test } from 'vitest';
import {
filesToStr,
strToFiles,
createPlaygroundShareUrl,
compressFiles,
parseCompressedFiles,
createPlaygroundShareUrl,
dictionary,
filesToStr,
parseCompressedFiles,
parsePlaygroundShareUrl,
strToFiles,
} from './repl-share-url';
import { strFromU8 } from 'fflate';

const data = {
version: '1.2.3',
Expand Down Expand Up @@ -64,8 +65,86 @@ test('createPlaygroundShareUrl 2', () => {
});

test('dictionary is unchanged', () => {
assert.equal(
strFromU8(dictionary),
"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"
const dictionaryAsString = strFromU8(dictionary);
// !!! THIS DICTIONARY MUST NEVER CHANGE - ONLY ALLOW PREPENDING !!!
expect(dictionaryAsString).toMatchInlineSnapshot(`
"8|/app.tsx|149|import { component$ } from '@qwik.dev/core';

export default component$(() => {
return (
<div>
<h1>Hello from Qwik!</h1>
</div>
);
|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';

export default component$(() => {
return <p>Hello Qwik</p>;
});
|17|/entry.server.tsx|201|import { renderToString, type RenderOptions } from '@builder.io/qwik/server';
import { Root } from './root';

export default function (opts: RenderOptions) {
return renderToString(<Root />, opts);
}
|9|/root.tsx|192|import App from './app';

export const Root = () => {
return (
<>
<head>
<title>Hello Qwik</title>
</head>
<body>
<App />
</body>
</>
);
};
"
`);
});

test('previous URLs still work', () => {
expect(parsePlaygroundShareUrl('f=G000o4mG5EQDAA')).toHaveProperty(
'files',
// DO NOT UPDATE THIS TEST - all these URLs must work forever
expect.arrayContaining([
expect.objectContaining({
path: '/app.tsx',
code: "import { component$ } from '@builder.io/qwik';\n\nexport default component$(() => {\n return <p>Hello Qwik</p>;\n});\n",
}),
])
);
expect(
parsePlaygroundShareUrl(
'f=Q0o0xgaW2BKNDrDkqNCB15QUpyFIgKTl51uBeGA%2BKO%2BBIwaW0W1A6SI%2FDWQzyKm1wKBDVwyU0lAqUNJRqE4GFc3AqLNSCnENDlGq1QTpAGJ43a5RDa6oa0FOgBsDbxkAXQIMCqAWMIktXqqBSvRgNoNMRg7C0XQ%2FJNM9AA'
)
).toHaveProperty(
'files',
// DO NOT UPDATE THIS TEST - all these URLs must work forever
expect.arrayContaining([
expect.objectContaining({
path: '/app.tsx',
code: `import { component$, jsx, useTask$ } from '@builder.io/qwik';

export default component$(() => {
const foo:{
contents: ReturnType<typeof jsx>
} = {
contents: jsx("p", {children:"TEST"})
}
useTask$(({track}) =>{
console.log(foo);
});
return (
<>
{foo.contents}
</>
);
});
`,
}),
])
);
});
Loading