feat: expose the page's query parameters to full-code apps as ctx.query (#12179)

This commit is contained in:
AlexRV12
2026-11-03 17:10:46 +01:00
committed by GitHub
parent c8930fcb07
commit ab15324008
14 changed files with 75 additions and 26 deletions
+1 -1
View File
@@ -230,7 +230,7 @@ const createHTML = (jsPath: string, cssPath: string, appCtx: unknown) => `
</div>
</div>
</div>
<script>window.ctx = ${JSON.stringify(appCtx).replace(/</g, "\\u003c")};</script>
<script>window.ctx = ${JSON.stringify(appCtx).replace(/</g, "\\u003c")}; window.ctx.query = Object.fromEntries(new URLSearchParams(location.search));</script>
<script src="${jsPath}"></script>
<script>
// Live reload via EventSource
+2
View File
@@ -6782,6 +6782,8 @@ Svelte (\`index.ts\`): \`mount(App, { target: document.getElementById('root')! }
**Set the browser tab title with \`document.title = '...'\`** (or a \`<title>\` the framework renders into \`<head>\`). The app has no \`index.html\` of its own, so a \`<title>\` written there is never served; the deployed app's page shows whatever \`document.title\` holds, and follows it when it changes.
**Read the page's context from \`window.ctx\`**: \`ctx\` is the viewer (absent for anonymous visitors), \`workspace\` and \`path\` the app's (\`path\` is not set under \`wmill app dev\`), and \`query\` the page URL's query parameters as strings (\`…/apps/get/u/me/app?customer=42\` gives \`window.ctx.query.customer === '42'\`, and no query gives \`{}\`). Read it there, not from \`window.location\`, which in a sandboxed app is not the page's address. It is read once when the app loads.
**Always begin every React file (\`.tsx\`/\`.jsx\`) that uses JSX with \`import React from 'react'\`.** esbuild uses the classic JSX transform, so \`React\` must be in scope wherever JSX appears — a missing import compiles fine but throws \`React is not defined\` at runtime, leaving a blank screen.
### Generated bindings (\`wmill.d.ts\` / \`wmill.ts\`)