Skip to content

Commit

Permalink
chore(web): Fix .d.ts overwrite build issue (#10431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Apr 8, 2024
1 parent 4c2213b commit b379670
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
7 changes: 0 additions & 7 deletions packages/web/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
import type { NormalizedCacheObject } from '@apollo/client'
import type { HelmetServerState } from 'react-helmet-async'

import type { TagDescriptor } from '@redwoodjs/web'

declare global {
var __REDWOOD__PRERENDERING: boolean
var __REDWOOD__HELMET_CONTEXT: { helmet?: HelmetServerState }
var __REDWOOD__APP_TITLE: string
var __REDWOOD__APOLLO_STATE: NormalizedCacheObject

var __REDWOOD__ASSET_MAP: {
css?: string[]
meta?: TagDescriptor[]
}

// Provided by Vite.config, or Webpack in the user's project
var RWJS_ENV: {
RWJS_API_GRAPHQL_URL: string
Expand Down
27 changes: 20 additions & 7 deletions packages/web/src/components/htmlTags.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { Fragment } from 'react'

const extractFromAssetMap = (key: 'css' | 'meta') => {
declare const window: {
__REDWOOD__ASSET_MAP: {
css?: string[]
meta?: TagDescriptor[]
}
} & Window

const extractCssFromAssetMap = () => {
if (typeof window !== 'undefined') {
return window.__REDWOOD__ASSET_MAP?.css
}

return undefined
}

const extractMetaFromAssetMap = () => {
if (typeof window !== 'undefined') {
return window?.__REDWOOD__ASSET_MAP?.[key]
return window.__REDWOOD__ASSET_MAP?.meta
}

return null
return undefined
}

function addSlashIfNeeded(path: string): string {
Expand All @@ -18,9 +33,7 @@ function addSlashIfNeeded(path: string): string {

/** CSS is a specialised metatag */
export const Css = ({ css }: { css: string[] }) => {
const cssLinks = (css || extractFromAssetMap('css') || []).map(
addSlashIfNeeded,
)
const cssLinks = (css || extractCssFromAssetMap() || []).map(addSlashIfNeeded)

return (
<>
Expand Down Expand Up @@ -99,7 +112,7 @@ interface MetaProps {
}

export const Meta = ({ tags }: MetaProps) => {
const metaTags = tags || extractFromAssetMap('meta') || []
const metaTags = tags || extractMetaFromAssetMap() || []

return (
<>
Expand Down

0 comments on commit b379670

Please sign in to comment.