-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#7923): do not throw on user { type } object
- Loading branch information
1 parent
1b65623
commit 79ce6d0
Showing
8 changed files
with
114 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Do not throw Error when users pass an object with a "type" property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { HydrationMetadata } from '../hydration.js'; | ||
|
||
const RenderInstructionSymbol = Symbol.for('astro:render'); | ||
|
||
export type RenderDirectiveInstruction = { | ||
type: 'directive'; | ||
hydration: HydrationMetadata; | ||
}; | ||
|
||
export type RenderHeadInstruction = { | ||
type: 'head'; | ||
}; | ||
|
||
export type MaybeRenderHeadInstruction = { | ||
type: 'maybe-head'; | ||
}; | ||
|
||
export type RenderInstruction = | ||
| RenderDirectiveInstruction | ||
| RenderHeadInstruction | ||
| MaybeRenderHeadInstruction; | ||
|
||
export function createRenderInstruction(instruction: RenderDirectiveInstruction): RenderDirectiveInstruction; | ||
export function createRenderInstruction(instruction: RenderHeadInstruction): RenderHeadInstruction; | ||
export function createRenderInstruction(instruction: MaybeRenderHeadInstruction): MaybeRenderHeadInstruction; | ||
export function createRenderInstruction(instruction: { type: string }): RenderInstruction { | ||
return Object.defineProperty(instruction as RenderInstruction, RenderInstructionSymbol, { value: true }); | ||
} | ||
|
||
export function isRenderInstruction(chunk: any): chunk is RenderInstruction { | ||
return chunk && typeof chunk === 'object' && chunk[RenderInstructionSymbol]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { createFs, createRequestAndResponse, runInContainer } from '../test-utils.js'; | ||
|
||
const root = new URL('../../fixtures/alias/', import.meta.url); | ||
|
||
describe('core/render chunk', () => { | ||
it('does not throw on user object with type', async () => { | ||
const fs = createFs( | ||
{ | ||
'/src/pages/index.astro': ` | ||
--- | ||
const value = { type: 'foobar' } | ||
--- | ||
<div id="chunk">{value}</div> | ||
`, | ||
}, | ||
root | ||
); | ||
|
||
await runInContainer( | ||
{ | ||
fs, | ||
inlineConfig: { | ||
root: fileURLToPath(root), | ||
logLevel: 'silent', | ||
integrations: [], | ||
}, | ||
}, | ||
async (container) => { | ||
const { req, res, done, text } = createRequestAndResponse({ | ||
method: 'GET', | ||
url: '/', | ||
}); | ||
container.handle(req, res); | ||
|
||
await done; | ||
try { | ||
const html = await text(); | ||
const $ = cheerio.load(html); | ||
const target = $('#chunk'); | ||
|
||
expect(target).not.to.be.undefined; | ||
expect(target.text()).to.equal('[object Object]'); | ||
} catch (e) { | ||
expect(false).to.be.ok; | ||
} | ||
} | ||
); | ||
}); | ||
}); |