Skip to content

Commit

Permalink
Merge pull request #198 from Shopify/fd-fix-public-assets
Browse files Browse the repository at this point in the history
fix: run Hydrogen middleware after Vite handles static assets
  • Loading branch information
frandiox authored Nov 11, 2021
2 parents ffb98a6 + 474a63a commit b1b5ba2
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function ({ifFeature}: TemplateOptions) {
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
${ifFeature(
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hydrogen App</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
Expand Down
File renamed without changes
1 change: 1 addition & 0 deletions packages/hydrogen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

- fix: let Vite handle public assets in development
- fix: new lines in hydration request break JSON.parse
- fix(#201): normalize POSIX separators to support windows
- fix: scroll to top on app first load
Expand Down
5 changes: 2 additions & 3 deletions packages/hydrogen/src/framework/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ function shouldInterceptRequest(
isReactHydrationRequest: boolean
) {
return (
(/text\/html|application\/hydrogen/.test(request.headers['accept'] ?? '') ||
isReactHydrationRequest) &&
request.url !== '/favicon.ico'
/text\/html|application\/hydrogen/.test(request.headers['accept'] ?? '') ||
isReactHydrationRequest
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ export default (
return await server.transformIndexHtml(url, indexHtml);
}

server.middlewares.use(
hydrogenMiddleware({
dev: true,
shopifyConfig,
indexTemplate: getIndexTemplate,
getServerEntrypoint: async () =>
await server.ssrLoadModule(resolve('./src/entry-server')),
devServer: server,
cache: pluginOptions?.devCache
? (new InMemoryCache() as unknown as Cache)
: undefined,
})
);
return () =>
server.middlewares.use(
hydrogenMiddleware({
dev: true,
shopifyConfig,
indexTemplate: getIndexTemplate,
getServerEntrypoint: async () =>
await server.ssrLoadModule(resolve('./src/entry-server')),
devServer: server,
cache: pluginOptions?.devCache
? (new InMemoryCache() as unknown as Cache)
: undefined,
})
);
},
} as Plugin;
};
2 changes: 1 addition & 1 deletion packages/playground/server-components-worker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hydrogen App</title>
</head>
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/server-components/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hydrogen App</title>
</head>
Expand Down
15 changes: 15 additions & 0 deletions packages/playground/server-components/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b1b5ba2

Please sign in to comment.