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
3 changes: 2 additions & 1 deletion adex/runtime/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ const withComponents = routes.map(d => {
function ComponentWrapper({ url = '' }) {
return h(
LocationProvider,
//@ts-expect-error no types for non-jsx function
{ url: url },
h(
ErrorBoundary,
{},
h(
Router,
{ url: url },
{},
withComponents.map(d =>
h(Route, { path: d.routePath, component: d.component })
)
Expand Down
12 changes: 9 additions & 3 deletions adex/runtime/handler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CONSTANTS, emitToHooked } from 'adex/hook'
import { prepareRequest, prepareResponse } from 'adex/http'
import { toStatic } from 'adex/ssr'
import { LocationProvider, ErrorBoundary, Router } from 'adex/router'
import { renderToString } from 'adex/utils/isomorphic'
import { h } from 'preact'

Expand All @@ -21,7 +20,8 @@ export async function handler(req, res) {
prepareRequest(req)
prepareResponse(res)

const [baseURL] = req.url.split('?')
const [url, search] = req.url.split('?')
const baseURL = normalizeRequestUrl(url)

const { metas, links, title, lang } = toStatic()

Expand Down Expand Up @@ -60,7 +60,9 @@ export async function handler(req, res) {
// @ts-expect-error
global.location = new URL(req.url, 'http://localhost')

const rendered = await renderToString(h(App, { url: req.url }))
const rendered = await renderToString(
h(App, { url: [baseURL, search].filter(Boolean).join('?') })
)

const htmlString = HTMLTemplate({
metas,
Expand Down Expand Up @@ -148,3 +150,7 @@ const stringify = (title, metas, links) => {
${stringifyTag('link', links)}
`
}

function normalizeRequestUrl(url) {
return url.replace(/\/(index\.html)$/, '/')
}
2 changes: 1 addition & 1 deletion adex/src/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function fonts({ providers = [], families = [] } = {}) {
},
async transform(code, id) {
const resolvedData = await this.resolve('virtual:adex:client')
if (id === resolvedData.id) {
if (resolvedData?.id == id) {
return {
code: `import "${fontVirtualId}";\n` + code,
}
Expand Down
Loading
Loading