Skip to content

Commit

Permalink
fix: escape vite asset import suffixes
Browse files Browse the repository at this point in the history
Add the regix to exclude all vite asset import suffixes,
might be better done in the @hono/vite-dev-server, but this
fixes the issue for now
  • Loading branch information
barakcodes committed Dec 3, 2024
1 parent 6963bfb commit c799af0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/node/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { LoaderFunctionArgs } from '@remix-run/node'
import { useLoaderData } from '@remix-run/react'
import logoDark from '/logo-dark.png?inline'

export const loader = (args: LoaderFunctionArgs) => {
const extra = args.context.extra
Expand All @@ -14,6 +15,12 @@ export default function Index() {
<h1>Remix and Hono</h1>
<h2>URL is {url}</h2>
<h3>Extra is {extra}</h3>
<div >
<img
src={logoDark}
alt="Remix"
/>
</div>
</div>
)
}
5 changes: 5 additions & 0 deletions examples/node/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ test('Should return 200 response - /', async ({ page }) => {

const contentH3 = await page.textContent('h3')
expect(contentH3).toBe('Extra is stuff')

const images = await page.$$('img')
expect(images.length).toBe(1)
const imageResponse = await page.goto('/logo-dark.png')
expect(imageResponse?.status()).toBe(200)
})

test('Should return 200 response - /api', async ({ page }) => {
Expand Down
Binary file added examples/node/public/logo-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default (options: Options): Plugin => {
'/assets/**',
'/app/**',
'/src/app/**',
// matches for vite's import assets suffixes
/\?(inline|url|no-inline|raw)/,
],
injectClientScript: false,
loadModule: async (server, entry) => {
Expand Down

0 comments on commit c799af0

Please sign in to comment.