Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 16 additions & 15 deletions packages/react-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
MillionProps,
Options,
} from '../types';
import { renderReactScope } from '../react/utils';
import { experimental_options } from '../experimental';
import { useContainer, useNearestParent } from '../react/its-fine';
import { useSSRSafeId } from './utils';
Expand Down Expand Up @@ -179,8 +180,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 @@ -309,25 +310,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 @@ -337,7 +338,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