Skip to content

Commit

Permalink
Fixes solid (#1634)
Browse files Browse the repository at this point in the history
* Fixes solid

* Rename the test

* Rebase with next

* Skip solid test for now
  • Loading branch information
matthewp authored Oct 22, 2021
1 parent 2f43bdd commit 2c1d85e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
6 changes: 1 addition & 5 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,8 @@ async function viteSSRDeps(deps: string[]): Promise<{ external: Set<string>; noE
return;
}

// if ESM, try noExternal
if (packageJSON.type === 'module') {
noExternal.add(spec);
}
// otherwise, assume external by default
else {
if (packageJSON.type !== 'module') {
external.add(spec);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createSignal } from 'solid-js';

export default function Counter() {
const [count] = createSignal(0);

return (
<>
<div class="hello">Hello world - {count}</div>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
import Hello from '../components/Hello.jsx';
---
<html>
<head><title>Solid</title></head>
<body>
<div><Hello /></div>
</body>
</html>
23 changes: 23 additions & 0 deletions packages/astro/test/solid-component.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe.skip('Solid component', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
projectRoot: './fixtures/solid-component/',
renderers: ['@astrojs/renderer-solid'],
});
await fixture.build();
});

it('Can load a component', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);

// test 1: Works
expect($('.hello')).to.have.lengthOf(1);
});
});
8 changes: 7 additions & 1 deletion packages/renderers/renderer-react/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import StaticHtml from './static-html.js';

const reactTypeof = Symbol.for('react.element');

function errorIsComingFromPreactComponent(err) {
return err.message && err.message.startsWith("Cannot read property '__H'");
}

function check(Component, props, children) {
if (typeof Component !== 'function') return false;

Expand All @@ -20,7 +24,9 @@ function check(Component, props, children) {
isReactComponent = true;
}
} catch (err) {
error = err;
if(!errorIsComingFromPreactComponent(err)) {
error = err;
}
}

return React.createElement('div');
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers/renderer-solid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
jsxTransformOptions: async ({ ssr }) => {
const [{ default: solid }] = await Promise.all([import('babel-preset-solid')]);
const options = {
presets: [solid({}, { generate: isSSR ? 'ssr' : 'dom', hydratable: true })],
presets: [solid({}, { generate: ssr ? 'ssr' : 'dom', hydratable: true })],
plugins: [],
};

Expand Down

0 comments on commit 2c1d85e

Please sign in to comment.