From d700a1c44a53e66620fa366b5665215d5e534bf2 Mon Sep 17 00:00:00 2001 From: Sreekanth Nagareddy Date: Mon, 10 Mar 2025 12:40:19 +0530 Subject: [PATCH 1/3] deprecated event$ --- packages/docs/src/components/theme-toggle/theme-toggle.tsx | 4 ++-- packages/docs/src/routes/api/qwik/api.json | 4 ++-- packages/docs/src/routes/api/qwik/index.md | 6 +++++- packages/qwik-city/src/runtime/src/spa-init.ts | 4 ++-- packages/qwik/src/core/api.md | 2 +- packages/qwik/src/core/qrl/qrl.public.ts | 2 +- starters/apps/e2e/src/components/render/render.tsx | 4 ++-- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/docs/src/components/theme-toggle/theme-toggle.tsx b/packages/docs/src/components/theme-toggle/theme-toggle.tsx index 2b8433c5f75..8cc071dd367 100644 --- a/packages/docs/src/components/theme-toggle/theme-toggle.tsx +++ b/packages/docs/src/components/theme-toggle/theme-toggle.tsx @@ -1,4 +1,4 @@ -import { component$, event$, useContext, useStyles$ } from '@builder.io/qwik'; +import { component$, $, useContext, useStyles$ } from '@builder.io/qwik'; import { SunAndMoon } from './sun-and-moon'; import { themeStorageKey } from '../router-head/theme-script'; import themeToggle from './theme-toggle.css?inline'; @@ -45,7 +45,7 @@ export const ThemeToggle = component$(() => { useStyles$(themeToggle); const state = useContext(GlobalStore); - const onClick$ = event$(() => { + const onClick$ = $(() => { state.theme = state.theme === 'light' ? 'dark' : 'light'; setPreference(state.theme); }); diff --git a/packages/docs/src/routes/api/qwik/api.json b/packages/docs/src/routes/api/qwik/api.json index c913d82b698..9ccaee54229 100644 --- a/packages/docs/src/routes/api/qwik/api.json +++ b/packages/docs/src/routes/api/qwik/api.json @@ -819,7 +819,7 @@ } ], "kind": "Function", - "content": "```typescript\nevent$: (qrl: T) => QRL\n```\n\n\n\n\n
\n\nParameter\n\n\n\n\nType\n\n\n\n\nDescription\n\n\n
\n\nqrl\n\n\n\n\nT\n\n\n\n\n\n
\n**Returns:**\n\n[QRL](#qrl)<T>", + "content": "> Warning: This API is now obsolete.\n> \n> will be removed in v2 use $\n> \n\n\n```typescript\nevent$: (qrl: T) => QRL\n```\n\n\n\n\n
\n\nParameter\n\n\n\n\nType\n\n\n\n\nDescription\n\n\n
\n\nqrl\n\n\n\n\nT\n\n\n\n\n\n
\n**Returns:**\n\n[QRL](#qrl)<T>", "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/qrl/qrl.public.ts", "mdFile": "qwik.event_.md" }, @@ -1774,7 +1774,7 @@ } ], "kind": "Function", - "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\n\n
\n\nParameter\n\n\n\n\nType\n\n\n\n\nDescription\n\n\n
\n\nopts\n\n\n\n\n{ base?: string; scope?: string; path?: string; verbose?: boolean; fetchBundleGraph?: boolean; nonce?: string; }\n\n\n\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
\n**Returns:**\n\n[JSXNode](#jsxnode)<'script'>", + "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\n\n
\n\nParameter\n\n\n\n\nType\n\n\n\n\nDescription\n\n\n
\n\nopts\n\n\n\n\n{ base?: string; scope?: string; path?: string; verbose?: boolean; fetchBundleGraph?: boolean; nonce?: string; }\n\n\n\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
\n**Returns:**\n\nJSXNode<'script'>", "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts", "mdFile": "qwik.prefetchserviceworker.md" }, diff --git a/packages/docs/src/routes/api/qwik/index.md b/packages/docs/src/routes/api/qwik/index.md index 88380b14447..411e51a82f7 100644 --- a/packages/docs/src/routes/api/qwik/index.md +++ b/packages/docs/src/routes/api/qwik/index.md @@ -2168,6 +2168,10 @@ any \| undefined ## event$ +> Warning: This API is now obsolete. +> +> will be removed in v2 use $ + ```typescript event$: (qrl: T) => QRL; ``` @@ -3657,7 +3661,7 @@ Options for the prefetch service worker. **Returns:** -[JSXNode](#jsxnode)<'script'> +JSXNode<'script'> [Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts) diff --git a/packages/qwik-city/src/runtime/src/spa-init.ts b/packages/qwik-city/src/runtime/src/spa-init.ts index 183e3345d33..9f34edf1fb4 100644 --- a/packages/qwik-city/src/runtime/src/spa-init.ts +++ b/packages/qwik-city/src/runtime/src/spa-init.ts @@ -3,7 +3,7 @@ import type { ScrollHistoryState } from './scroll-restoration'; import type { ScrollState } from './types'; import { isDev } from '@builder.io/qwik'; -import { event$ } from '@builder.io/qwik'; +import { $ } from '@builder.io/qwik'; // TODO Dedupe handler code from here and QwikCityProvider? // TODO Navigation API; check for support & simplify. @@ -14,7 +14,7 @@ import { event$ } from '@builder.io/qwik'; // - Robust, fully relies only on history. (scrollRestoration = 'manual') // ! DO NOT IMPORT OR USE ANY EXTERNAL REFERENCES IN THIS SCRIPT. -export default event$((_: Event, el: Element) => { +export default $((_: Event, el: Element) => { const win: ClientSPAWindow = window; const spa = '_qCitySPA'; const initPopstate = '_qCityInitPopstate'; diff --git a/packages/qwik/src/core/api.md b/packages/qwik/src/core/api.md index 286a6322f10..fcd292f24f3 100644 --- a/packages/qwik/src/core/api.md +++ b/packages/qwik/src/core/api.md @@ -230,7 +230,7 @@ export interface ErrorBoundaryStore { error: any | undefined; } -// @public (undocumented) +// @public @deprecated (undocumented) export const event$: (qrl: T) => QRL; // @public diff --git a/packages/qwik/src/core/qrl/qrl.public.ts b/packages/qwik/src/core/qrl/qrl.public.ts index 2d3aa303dc8..1c276b5fda2 100644 --- a/packages/qwik/src/core/qrl/qrl.public.ts +++ b/packages/qwik/src/core/qrl/qrl.public.ts @@ -270,7 +270,7 @@ export const eventQrl = (qrl: QRL): QRL => { return qrl; }; -/** @public */ +/** @public @deprecated will be removed in v2 use $ */ export const event$ = implicit$FirstArg(eventQrl); /** @alpha */ diff --git a/starters/apps/e2e/src/components/render/render.tsx b/starters/apps/e2e/src/components/render/render.tsx index 08ea6ad2268..91b3c1c2180 100644 --- a/starters/apps/e2e/src/components/render/render.tsx +++ b/starters/apps/e2e/src/components/render/render.tsx @@ -4,7 +4,7 @@ import { useStore, useStylesScoped$, useTask$, - event$, + $, h, jsx, SkipRender, @@ -549,7 +549,7 @@ export const Issue3398 = component$(() => { export const Issue3479 = component$(() => { const count = useSignal(0); const attributes = { - onClick$: event$(() => count.value++), + onClick$: $(() => count.value++), }; const countStr = String(count.value) + ""; return ( From 2f31720d80cbc319e9be6c8b5e684c00d39c91c1 Mon Sep 17 00:00:00 2001 From: Sreekanth Nagareddy Date: Tue, 11 Mar 2025 11:05:52 +0530 Subject: [PATCH 2/3] review fix --- packages/docs/src/routes/api/qwik/api.json | 4 ++-- packages/docs/src/routes/api/qwik/index.md | 4 ++-- packages/qwik-city/src/runtime/src/spa-init.ts | 7 ++++++- packages/qwik/src/core/qrl/qrl.public.ts | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/docs/src/routes/api/qwik/api.json b/packages/docs/src/routes/api/qwik/api.json index 9ccaee54229..af57e23e5dc 100644 --- a/packages/docs/src/routes/api/qwik/api.json +++ b/packages/docs/src/routes/api/qwik/api.json @@ -819,7 +819,7 @@ } ], "kind": "Function", - "content": "> Warning: This API is now obsolete.\n> \n> will be removed in v2 use $\n> \n\n\n```typescript\nevent$: (qrl: T) => QRL\n```\n\n\n\n\n
\n\nParameter\n\n\n\n\nType\n\n\n\n\nDescription\n\n\n
\n\nqrl\n\n\n\n\nT\n\n\n\n\n\n
\n**Returns:**\n\n[QRL](#qrl)<T>", + "content": "> Warning: This API is now obsolete.\n> \n> It will be removed in v2. Instead, use `$()`, and inside the function add `if (isServer) { return; }`\n> \n\n\n```typescript\nevent$: (qrl: T) => QRL\n```\n\n\n\n\n
\n\nParameter\n\n\n\n\nType\n\n\n\n\nDescription\n\n\n
\n\nqrl\n\n\n\n\nT\n\n\n\n\n\n
\n**Returns:**\n\n[QRL](#qrl)<T>", "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/qrl/qrl.public.ts", "mdFile": "qwik.event_.md" }, @@ -1774,7 +1774,7 @@ } ], "kind": "Function", - "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\n\n
\n\nParameter\n\n\n\n\nType\n\n\n\n\nDescription\n\n\n
\n\nopts\n\n\n\n\n{ base?: string; scope?: string; path?: string; verbose?: boolean; fetchBundleGraph?: boolean; nonce?: string; }\n\n\n\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
\n**Returns:**\n\nJSXNode<'script'>", + "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\n\n
\n\nParameter\n\n\n\n\nType\n\n\n\n\nDescription\n\n\n
\n\nopts\n\n\n\n\n{ base?: string; scope?: string; path?: string; verbose?: boolean; fetchBundleGraph?: boolean; nonce?: string; }\n\n\n\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
\n**Returns:**\n\n[JSXNode](#jsxnode)<'script'>", "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts", "mdFile": "qwik.prefetchserviceworker.md" }, diff --git a/packages/docs/src/routes/api/qwik/index.md b/packages/docs/src/routes/api/qwik/index.md index 411e51a82f7..2e72a10c13b 100644 --- a/packages/docs/src/routes/api/qwik/index.md +++ b/packages/docs/src/routes/api/qwik/index.md @@ -2170,7 +2170,7 @@ any \| undefined > Warning: This API is now obsolete. > -> will be removed in v2 use $ +> It will be removed in v2. Instead, use `$()`, and inside the function add `if (isServer) { return; }` ```typescript event$: (qrl: T) => QRL; @@ -3661,7 +3661,7 @@ Options for the prefetch service worker. **Returns:** -JSXNode<'script'> +[JSXNode](#jsxnode)<'script'> [Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/components/prefetch.ts) diff --git a/packages/qwik-city/src/runtime/src/spa-init.ts b/packages/qwik-city/src/runtime/src/spa-init.ts index 9f34edf1fb4..af0b2083c98 100644 --- a/packages/qwik-city/src/runtime/src/spa-init.ts +++ b/packages/qwik-city/src/runtime/src/spa-init.ts @@ -2,7 +2,7 @@ import type { ClientSPAWindow } from './qwik-city-component'; import type { ScrollHistoryState } from './scroll-restoration'; import type { ScrollState } from './types'; -import { isDev } from '@builder.io/qwik'; +import { isDev, isServer } from '@builder.io/qwik'; import { $ } from '@builder.io/qwik'; // TODO Dedupe handler code from here and QwikCityProvider? @@ -21,6 +21,11 @@ export default $((_: Event, el: Element) => { const initAnchors = '_qCityInitAnchors'; const initVisibility = '_qCityInitVisibility'; const initScroll = '_qCityInitScroll'; + + if (isServer) { + return; + } + if ( !win[spa] && !win[initPopstate] && diff --git a/packages/qwik/src/core/qrl/qrl.public.ts b/packages/qwik/src/core/qrl/qrl.public.ts index 1c276b5fda2..6d36d9399aa 100644 --- a/packages/qwik/src/core/qrl/qrl.public.ts +++ b/packages/qwik/src/core/qrl/qrl.public.ts @@ -270,7 +270,7 @@ export const eventQrl = (qrl: QRL): QRL => { return qrl; }; -/** @public @deprecated will be removed in v2 use $ */ +/** @public @deprecated It will be removed in v2. Instead, use `$()`, and inside the function add `if (isServer) { return; }` */ export const event$ = implicit$FirstArg(eventQrl); /** @alpha */ From 9644bccfc456fa573638dd88e0f7f49845c41c06 Mon Sep 17 00:00:00 2001 From: Sreekanth Nagareddy Date: Tue, 11 Mar 2025 11:08:54 +0530 Subject: [PATCH 3/3] added change set --- .changeset/hip-lemons-move.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hip-lemons-move.md diff --git a/.changeset/hip-lemons-move.md b/.changeset/hip-lemons-move.md new file mode 100644 index 00000000000..040c95e6e75 --- /dev/null +++ b/.changeset/hip-lemons-move.md @@ -0,0 +1,5 @@ +--- +'@builder.io/qwik': patch +--- + +Deprecated event$, it will be removed in v2. Instead, use `$()`, and inside the function add `if (isServer) { return; }`