Skip to content

Commit e1c4e03

Browse files
committed
chore: deprecate and unregister service workers
1 parent 884802f commit e1c4e03

File tree

50 files changed

+113
-2871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+113
-2871
lines changed

.changeset/yellow-frogs-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@builder.io/qwik-city': minor
3+
---
4+
5+
CHORE: the service workers have been deprecated and replaced with entries that unregister them. If you have it enabled in production, you can remove it after a while once you are sure all your users have the new version.

packages/docs/src/routes/api/qwik-city/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@
782782
}
783783
],
784784
"kind": "Function",
785-
"content": "```typescript\nServiceWorkerRegister: (props: {\n nonce?: string;\n}) => import(\"@builder.io/qwik\").JSXNode<\"script\">\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nprops\n\n\n</td><td>\n\n{ nonce?: string; }\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nimport(\"@builder.io/qwik\").JSXNode&lt;\"script\"&gt;",
785+
"content": "Loads the service workers that are defined in the routes. Any file named `service-worker.*` (all JS extensions are allowed) will be picked up, bundled into a separate file, and registered as a service worker.\n\n\n```typescript\nServiceWorkerRegister: (props: {\n nonce?: string;\n}) => import(\"packages/qwik/dist\").JSXOutput\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nprops\n\n\n</td><td>\n\n{ nonce?: string; }\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nimport(\"packages/qwik/dist\").JSXOutput",
786786
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/sw-component.tsx",
787787
"mdFile": "qwik-city.serviceworkerregister.md"
788788
},

packages/docs/src/routes/api/qwik-city/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,9 +2269,11 @@ export type ServerQRL<T extends ServerFunction> = QRL<
22692269
22702270
## ServiceWorkerRegister
22712271
2272+
Loads the service workers that are defined in the routes. Any file named `service-worker.*` (all JS extensions are allowed) will be picked up, bundled into a separate file, and registered as a service worker.
2273+
22722274
```typescript
22732275
ServiceWorkerRegister: (props: { nonce?: string }) =>
2274-
import("@builder.io/qwik").JSXNode<"script">;
2276+
import("packages/qwik/dist").JSXOutput;
22752277
```
22762278
22772279
<table><thead><tr><th>
@@ -2301,7 +2303,7 @@ props
23012303
</tbody></table>
23022304
**Returns:**
23032305
2304-
import("@builder.io/qwik").JSXNode&lt;"script"&gt;
2306+
import("packages/qwik/dist").JSXOutput
23052307
23062308
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/sw-component.tsx)
23072309

packages/docs/src/routes/api/qwik/api.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@
17601760
}
17611761
],
17621762
"kind": "Function",
1763-
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nLoad the prefetch graph for the container.\n\nEach Qwik container needs to include its own prefetch graph.\n\n\n```typescript\nPrefetchGraph: (opts?: {\n base?: string;\n manifestHash?: string;\n manifestURL?: string;\n nonce?: string;\n}) => JSXOutput\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nopts\n\n\n</td><td>\n\n{ base?: string; manifestHash?: string; manifestURL?: string; nonce?: string; }\n\n\n</td><td>\n\n_(Optional)_ Options for the loading prefetch graph.\n\n- `base` - Base of the graph. For a default installation this will default to the q:base value `/build/`<!-- -->. But if more than one MFE is installed on the page, then each MFE needs to have its own base. - `manifestHash` - Hash of the manifest file to load. If not provided the hash will be extracted from the container attribute `q:manifest-hash` and assume the default build file `${base}/q-bundle-graph-${manifestHash}.json`<!-- -->. - `manifestURL` - URL of the manifest file to load if non-standard bundle graph location name.\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[JSXOutput](#jsxoutput)",
1763+
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\n> Warning: This API is now obsolete.\n> \n> This is no longer needed as the preloading happens automatically in qrl-class. You can remove this component from your app.\n> \n\n\n```typescript\nPrefetchGraph: (opts?: {\n base?: string;\n manifestHash?: string;\n manifestURL?: string;\n nonce?: string;\n}) => JSXOutput\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nopts\n\n\n</td><td>\n\n{ base?: string; manifestHash?: string; manifestURL?: string; nonce?: string; }\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[JSXOutput](#jsxoutput)",
17641764
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts",
17651765
"mdFile": "qwik.prefetchgraph.md"
17661766
},
@@ -1774,7 +1774,7 @@
17741774
}
17751775
],
17761776
"kind": "Function",
1777-
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nInstall a service worker which will prefetch the bundles.\n\nThere can only be one service worker per page. Because there can be many separate Qwik Containers on the page each container needs to load its prefetch graph using `PrefetchGraph` component.\n\n\n```typescript\nPrefetchServiceWorker: (opts: {\n base?: string;\n scope?: string;\n path?: string;\n verbose?: boolean;\n fetchBundleGraph?: boolean;\n nonce?: string;\n}) => JSXNode<'script'>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nopts\n\n\n</td><td>\n\n{ base?: string; scope?: string; path?: string; verbose?: boolean; fetchBundleGraph?: boolean; nonce?: string; }\n\n\n</td><td>\n\nOptions for the prefetch service worker.\n\n- `base` - Base URL for the service worker `import.meta.env.BASE_URL` or `/`<!-- -->. Default is `import.meta.env.BASE_URL` - `scope` - Base URL for when the service-worker will activate. Default is `/` - `path` - Path to the service worker. Default is `qwik-prefetch-service-worker.js` unless you pass a path that starts with a `/` then the base is ignored. Default is `qwik-prefetch-service-worker.js` - `verbose` - Verbose logging for the service worker installation. Default is `false` - `nonce` - Optional nonce value for security purposes, defaults to `undefined`<!-- -->.\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[JSXNode](#jsxnode)<!-- -->&lt;'script'&gt;",
1777+
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\n> Warning: This API is now obsolete.\n> \n> This is no longer needed as the preloading happens automatically in qrl-class.ts. Leave this in your app for a while so it uninstalls existing service workers, but don't use it for new projects.\n> \n\n\n```typescript\nPrefetchServiceWorker: (opts: {\n base?: string;\n scope?: string;\n path?: string;\n verbose?: boolean;\n fetchBundleGraph?: boolean;\n nonce?: string;\n}) => JSXNode<'script'>\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nopts\n\n\n</td><td>\n\n{ base?: string; scope?: string; path?: string; verbose?: boolean; fetchBundleGraph?: boolean; nonce?: string; }\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\n[JSXNode](#jsxnode)<!-- -->&lt;'script'&gt;",
17781778
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts",
17791779
"mdFile": "qwik.prefetchserviceworker.md"
17801780
},

packages/docs/src/routes/api/qwik/index.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,9 +3559,9 @@ export interface ParamHTMLAttributes<T extends Element> extends Attrs<'base', T,
35593559
35603560
> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
35613561
3562-
Load the prefetch graph for the container.
3563-
3564-
Each Qwik container needs to include its own prefetch graph.
3562+
> Warning: This API is now obsolete.
3563+
>
3564+
> This is no longer needed as the preloading happens automatically in qrl-class. You can remove this component from your app.
35653565
35663566
```typescript
35673567
PrefetchGraph: (opts?: {
@@ -3595,9 +3595,7 @@ opts
35953595
35963596
</td><td>
35973597
3598-
_(Optional)_ Options for the loading prefetch graph.
3599-
3600-
- `base` - Base of the graph. For a default installation this will default to the q:base value `/build/`. But if more than one MFE is installed on the page, then each MFE needs to have its own base. - `manifestHash` - Hash of the manifest file to load. If not provided the hash will be extracted from the container attribute `q:manifest-hash` and assume the default build file `${base}/q-bundle-graph-${manifestHash}.json`. - `manifestURL` - URL of the manifest file to load if non-standard bundle graph location name.
3598+
_(Optional)_
36013599
36023600
</td></tr>
36033601
</tbody></table>
@@ -3611,9 +3609,9 @@ _(Optional)_ Options for the loading prefetch graph.
36113609
36123610
> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
36133611
3614-
Install a service worker which will prefetch the bundles.
3615-
3616-
There can only be one service worker per page. Because there can be many separate Qwik Containers on the page each container needs to load its prefetch graph using `PrefetchGraph` component.
3612+
> Warning: This API is now obsolete.
3613+
>
3614+
> This is no longer needed as the preloading happens automatically in qrl-class.ts. Leave this in your app for a while so it uninstalls existing service workers, but don't use it for new projects.
36173615
36183616
```typescript
36193617
PrefetchServiceWorker: (opts: {
@@ -3649,10 +3647,6 @@ opts
36493647
36503648
</td><td>
36513649
3652-
Options for the prefetch service worker.
3653-
3654-
- `base` - Base URL for the service worker `import.meta.env.BASE_URL` or `/`. Default is `import.meta.env.BASE_URL` - `scope` - Base URL for when the service-worker will activate. Default is `/` - `path` - Path to the service worker. Default is `qwik-prefetch-service-worker.js` unless you pass a path that starts with a `/` then the base is ignored. Default is `qwik-prefetch-service-worker.js` - `verbose` - Verbose logging for the service worker installation. Default is `false` - `nonce` - Optional nonce value for security purposes, defaults to `undefined`.
3655-
36563650
</td></tr>
36573651
</tbody></table>
36583652
**Returns:**

packages/docs/src/routes/docs/(qwik)/getting-started/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ bun run preview
614614
NOTE:
615615

616616
- Your application should now have a production build running on localhost:4173.
617-
- If you interact with the application now, the network tab of the dev tools should show that the bundles are instantly delivered from the [ServiceWorker cache](/docs/advanced/speculative-module-fetching/).
617+
- If you interact with the application now, the network tab of the dev tools should show that the bundles have been [preloaded](/docs/advanced/speculative-module-fetching/).
618618

619619
## Review
620620

@@ -628,4 +628,4 @@ For more on just how much you can achieve with Qwik, check out the dedicated doc
628628
- [Form actions](/docs/(qwikcity)/action/index.mdx) && [zod validation](/docs/(qwikcity)/action/index.mdx#validation-and-type-safety)
629629
- [State management](/docs/(qwik)/components/state/index.mdx)
630630
- [Tasks](/docs/(qwik)/components/tasks/index.mdx#use-usetask-when-you-need-to)
631-
- [ServiceWorker cache](/docs/(qwikcity)/advanced/speculative-module-fetching/index.mdx#pre-populating-the-cache-with-a-service-worker)
631+
- [Preloading](/docs/(qwikcity)/advanced/speculative-module-fetching/index.mdx)

packages/docs/src/routes/docs/(qwikcity)/advanced/content-security-policy/index.mdx

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,39 +69,6 @@ export const onRequest: RequestHandler = event => {
6969
};
7070
```
7171

72-
### Add it to the service worker as well
73-
74-
```tsx {12,22} /nonce/ title="src/root.ts"
75-
import { component$, useServerData } from "@builder.io/qwik";
76-
import {
77-
QwikCityProvider,
78-
RouterOutlet,
79-
ServiceWorkerRegister,
80-
} from "@builder.io/qwik-city";
81-
import { RouterHead } from "./components/router-head/router-head";
82-
import { isDev } from "@builder.io/qwik";
83-
84-
import "./global.css";
85-
86-
export default component$(() => {
87-
const nonce = useServerData<string | undefined>("nonce");
88-
return (
89-
<QwikCityProvider>
90-
<head>
91-
<meta charSet="utf-8" />
92-
{!isDev && <link rel="manifest" href={`${import.meta.env.BASE_URL}manifest.json`} />}
93-
94-
<RouterHead />
95-
</head>
96-
<body lang="en">
97-
<RouterOutlet />
98-
{!isDev && <ServiceWorkerRegister nonce={nonce} />}
99-
</body>
100-
</QwikCityProvider>
101-
);
102-
});
103-
```
104-
10572
### Custom scripts
10673

10774
If you have custom script tags that you need to add the nonce to, you can use the `useServerData` hook to get the nonce from the server and add it to your script tags.

0 commit comments

Comments
 (0)