diff options
author | 2021-08-24 13:38:07 -0400 | |
---|---|---|
committer | 2021-08-24 13:38:07 -0400 | |
commit | 9482fadeb88b8e1562ab67ffe244ec9c042f178d (patch) | |
tree | e0de69a00e83e4302bb89bbd730e09f3e2b26af8 | |
parent | d0e7fcfc0652c8e5b6af0b584838b605efb92a8a (diff) | |
download | astro-9482fadeb88b8e1562ab67ffe244ec9c042f178d.tar.gz astro-9482fadeb88b8e1562ab67ffe244ec9c042f178d.tar.zst astro-9482fadeb88b8e1562ab67ffe244ec9c042f178d.zip |
Fix resolution of Astro.resolve in nested components (#1213)
* Fix resolution of Astro.resolve in nested components
Components were previously tested, however nested folders were not.
* Adds a changeset
5 files changed, 14 insertions, 5 deletions
diff --git a/.changeset/violet-crabs-deny.md b/.changeset/violet-crabs-deny.md new file mode 100644 index 000000000..9a830e445 --- /dev/null +++ b/.changeset/violet-crabs-deny.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Makes sure Astro.resolve works in nested component folders diff --git a/packages/astro/src/compiler/index.ts b/packages/astro/src/compiler/index.ts index a84abf97f..ede2a62f2 100644 --- a/packages/astro/src/compiler/index.ts +++ b/packages/astro/src/compiler/index.ts @@ -169,10 +169,6 @@ async function __render(props, ...children) { value: (props[__astroInternal] && props[__astroInternal].isPage) || false, enumerable: true }, - resolve: { - value: (props[__astroContext] && props[__astroContext].resolve) || {}, - enumerable: true - }, request: { value: (props[__astroContext] && props[__astroContext].request) || {}, enumerable: true @@ -201,7 +197,6 @@ export async function __renderPage({request, children, props, css}) { value: { pageCSS: css, request, - resolve: __TopLevelAstro.resolve, createAstroRootUID(seed) { return seed + astroRootUIDCounter++; }, }, writable: false, diff --git a/packages/astro/test/astro-global.test.js b/packages/astro/test/astro-global.test.js index 5dbac151b..558e0157f 100644 --- a/packages/astro/test/astro-global.test.js +++ b/packages/astro/test/astro-global.test.js @@ -48,6 +48,7 @@ Global('Astro.resolve in development', async (context) => { const html = result.contents; const $ = doc(html); assert.equal($('img').attr('src'), '/_astro/src/images/penguin.png'); + assert.equal($('#inner-child img').attr('src'), '/_astro/src/components/nested/images/penguin.png'); }); Global.run(); diff --git a/packages/astro/test/fixtures/astro-global/src/components/nested/InnerChild.astro b/packages/astro/test/fixtures/astro-global/src/components/nested/InnerChild.astro new file mode 100644 index 000000000..9b1e5f40e --- /dev/null +++ b/packages/astro/test/fixtures/astro-global/src/components/nested/InnerChild.astro @@ -0,0 +1,6 @@ +--- +const penguinUrl = Astro.resolve('./images/penguin.png'); +--- +<div id="inner-child"> + <img src={penguinUrl} /> +</div>
\ No newline at end of file diff --git a/packages/astro/test/fixtures/astro-global/src/pages/resolve.astro b/packages/astro/test/fixtures/astro-global/src/pages/resolve.astro index df2b5f5cb..b545b184c 100644 --- a/packages/astro/test/fixtures/astro-global/src/pages/resolve.astro +++ b/packages/astro/test/fixtures/astro-global/src/pages/resolve.astro @@ -1,5 +1,6 @@ --- import Child from '../components/ChildResolve.astro'; +import InnerChild from '../components/nested/InnerChild.astro'; --- <html> @@ -8,5 +9,6 @@ import Child from '../components/ChildResolve.astro'; </head> <body> <Child /> + <InnerChild /> </body> </html>
\ No newline at end of file |