Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: remix warnings #969

Merged
merged 5 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 8 additions & 1 deletion packages/compiler/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ interface CompilerOutput {
map: BabelFileResult['map'];
}

let ssr = false

async function compile(
id: string,
code: string,
options: Options,
telemetryInstance: MillionTelemetry,
isServer?: boolean,
): Promise<CompilerOutput> {
if (isServer) {
// for frameworks like remix, even for client, we need to return react-server
ssr = true
}

displayIntro(options);

const plugins: ParserOptions['plugins'] = [
Expand Down Expand Up @@ -52,7 +59,7 @@ async function compile(
{
telemetry: telemetryInstance,
log: options.log,
server: isServer,
server: ssr,
hmr: options.hmr,
auto: options.auto,
rsc: options.rsc,
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">
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
Loading