Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(web): Fix .d.ts overwrite build issue #10431

Merged
merged 1 commit into from
Apr 8, 2024
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
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
Loading