Skip to content

Commit

Permalink
Fix: newline characters in Solid (#3505)
Browse files Browse the repository at this point in the history
* fix: remove source map consumption from babel transform

* refactor: move inputSourceMap to integration option

* tests: add newline ex to test build and dev

* chore: change back to babel.transformAsync

* chore: changeset
  • Loading branch information
bholmesdev authored Jun 2, 2022
1 parent 45ae85c commit 2b35650
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/real-dogs-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/solid-js': patch
---

Fix newline characters in SolidJS JSX attributes (ex: multiline CSS classes)
7 changes: 1 addition & 6 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,7 @@ export interface HydrateOptions {
value?: string;
}

export interface JSXTransformConfig {
/** Babel presets */
presets?: babel.PluginItem[];
/** Babel plugins */
plugins?: babel.PluginItem[];
}
export type JSXTransformConfig = Pick<babel.TransformOptions, 'presets' | 'plugins' | 'inputSourceMap'>;

export type JSXTransformFn = (options: {
mode: string;
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/vite-plugin-jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async function transformJSX({
sourceMaps: true,
configFile: false,
babelrc: false,
inputSourceMap: options.inputSourceMap,
});
// TODO: Be more strict about bad return values here.
// Should we throw an error instead? Should we never return `{code: ""}`?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Test introduced to ensure JSX is correctly transformed
// See https://github.com/withastro/astro/issues/3371
import { createSignal } from 'solid-js';

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

return (
<>
<div class="multiline
css-classes">Hello world - {count}</div>
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
import Hello from '../components/Hello.jsx';
import WithNewlines from '../components/WithNewlines.jsx';
---
<html>
<head><title>Solid</title></head>
<body>
<div>
<Hello client:load />
<WithNewlines client:load />
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions packages/integrations/solid/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function getRenderer(): AstroRenderer {
const options = {
presets: [solid({}, { generate: ssr ? 'ssr' : 'dom', hydratable: true })],
plugins: [],
// Otherwise, babel will try to consume the source map generated by esbuild
// This causes unexpected issues with newline characters: https://github.com/withastro/astro/issues/3371
// Note "vite-plugin-solid" does the same: https://github.com/solidjs/vite-plugin-solid/blob/master/src/index.ts#L344-L345
inputSourceMap: false as any,
};

return options;
Expand Down

0 comments on commit 2b35650

Please sign in to comment.