Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/compiler/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const unplugin = createUnplugin((options: Options = {}, meta) => {
return filter(id);
},
async transform(code: string, id: string) {
console.log('id', id)
const result = await compile(id, code, options, telemetryInstance, options.server);
return {
code: result.code || '',
Expand Down
31 changes: 16 additions & 15 deletions packages/react-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
MillionProps,
Options,
} from '../types';
import { renderReactScope } from '../react/utils';

let globalInfo;

Expand Down Expand Up @@ -136,8 +137,8 @@ export const importSource = (callback: () => void) => {

callback();
})
.catch(() => {
throw new Error('Failed to load Million.js');
.catch((e) => {
throw new Error('Failed to load Million.js: ' + e);
});
};

Expand Down Expand Up @@ -213,25 +214,25 @@ export function compiledBlock(
portals && portalCount > 0
? (props: MillionProps) => {
const [current] = useState<MillionPortal[]>(() => []);
// const [firstRender, setFirstRender] = useState(true)
const [firstRender, setFirstRender] = useState(true)

const derived = { ...props };

for (let i = 0; i < portalCount; i++) {
// const index = portals[i]!;
// derived[index] = renderReactScope(
// derived[index] as JSX.Element,
// false,
// current,
// i,
// );
const index = portals[i]!;
derived[index] = renderReactScope(
derived[index] as JSX.Element,
false,
current,
i,
);
}
const [targets] = useState<ReactPortal[]>([]);

// useEffect(() => {
// // showing targets for the first render causes hydration error!
// // setFirstRender(false)
// })
useEffect(() => {
// showing targets for the first render causes hydration error!
setFirstRender(false)
})
for (let i = 0, len = current.length; i < len; i++) {
targets[i] = current[i]!.portal;
}
Expand All @@ -241,7 +242,7 @@ export function compiledBlock(
{},
createElement(RenderBlock, derived),
// TODO: This should be uncommented, but doing that, value.reset would fail as it is undefined. This should be revisited
// !firstRender ? targets : undefined,
!firstRender ? targets : undefined,
);
}
: (props: MillionProps) => createElement(RenderBlock, props);
Expand Down
3 changes: 3 additions & 0 deletions website/pages/docs/install.en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ export default {
};
```
</Tab>
<Callout type="warning">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, here it is. My bad

The compiler will only try compiling `.jsx` or `.tsx` files and will not try doing any transformation to any other file. You either convert your file formats to those formats or use the [Manual Mode](/docs/manual-mode/manual-mode).
</Callout>

</Tabs>

Expand Down