Skip to content

Commit

Permalink
fix: encode the lazy compile path (#1276)
Browse files Browse the repository at this point in the history
* fix: serialize the lazy-loaded path.

* chore: add changeset

* fix: deps

* fix: error

---------

Co-authored-by: brightwu <[email protected]>
  • Loading branch information
callqh and wre232114 authored Jun 5, 2024
1 parent c2c6717 commit d9cb690
Show file tree
Hide file tree
Showing 19 changed files with 375 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-news-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@farmfe/core': patch
---

fix: encode the lazy compile path
4 changes: 3 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
registry = "https://registry.npmjs.org/"
auto-install-peers = false
auto-install-peers = false
electron-mirror="https://npmmirror.com/mirrors/electron/"
```
2 changes: 1 addition & 1 deletion crates/plugin_lazy_compilation/src/dynamic_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if (compilingModules.has(modulePath)) {
const queue = [...FarmModuleSystem.lazyCompilingQueue];
FarmModuleSystem.lazyCompilingQueue = [];
const paths = queue.map((item) => item.modulePath);
const url = `/__lazy_compile?paths=${paths.join(',')}&t=${Date.now()}${
const url = `/__lazy_compile?paths=${encodeURIComponent(paths.join(','))}&t=${Date.now()}${
isNodeLazyCompile ? '&node=true' : ''
}`;

Expand Down
1 change: 1 addition & 0 deletions examples/react-query/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# adapter vite-plugin-pages
14 changes: 14 additions & 0 deletions examples/react-query/farm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from '@farmfe/core';
import Pages from 'vite-plugin-pages';

export default defineConfig({
plugins: ['@farmfe/plugin-react'],
compilation:{
persistentCache:false,
},
vitePlugins:[
Pages({
resolver:'react'
}),
]
});
13 changes: 13 additions & 0 deletions examples/react-query/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="root"></div>
<script src="./src/index.tsx"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions examples/react-query/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@farmfe-examples/react-query",
"version": "1.0.0",
"private": true,
"dependencies": {
"core-js": "^3.36.1",
"react": "18",
"react-dom": "18",
"react-router": "^6.22.3",
"react-router-dom": "^6.22.3",
"@tanstack/react-query": "^5.32.0"
},
"devDependencies": {
"@farmfe/cli": "workspace:*",
"@farmfe/core": "workspace:*",
"@farmfe/plugin-react": "^1.0.1",
"@types/react": "18",
"@types/react-dom": "18",
"react-refresh": "^0.14.0",
"vite-plugin-pages": "^0.32.0",
"@tanstack/react-query-devtools": "^5.32.0"
},
"scripts": {
"dev": "farm start",
"start": "farm start",
"build": "farm build",
"preview": "farm preview"
}
}
Binary file added examples/react-query/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/react-query/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions examples/react-query/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

a {
font-weight: 500;
color: #9f1a8f;
text-decoration: inherit;
}
a:hover {
color: #9f1a8f;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #9f1a8f;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #9F1A8F;
}
button {
background-color: #f9f9f9;
}
}
25 changes: 25 additions & 0 deletions examples/react-query/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { Suspense } from 'react';
import { createRoot } from 'react-dom/client';
import { BrowserRouter as Router, useRoutes } from 'react-router-dom';
import './index.css';
import routes from '~react-pages';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

const queryClient = new QueryClient();

const container = document.querySelector('#root');
const root = createRoot(container);

function App() {
return <Suspense fallback={<p>Loading...</p>}>{useRoutes(routes)}</Suspense>;
}

root.render(
<QueryClientProvider client={queryClient}>
{/* <ReactQueryDevtools initialIsOpen={true} /> */}
<Router>
<App />
</Router>
</QueryClientProvider>
);
9 changes: 9 additions & 0 deletions examples/react-query/src/pages/about/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

const Main = () => {
return <div>
this is about page
</div>;
};

export default Main;
34 changes: 34 additions & 0 deletions examples/react-query/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import FarmLogo from '../assets/logo.png';
import reactLogo from '../assets/react.svg';
import './main.css';

export default function () {
const [count, setCount] = useState(0);
const go = useNavigate();

return (
<>
<div>
<a href="https://farmfe.org/" target="_blank" rel="noreferrer">
<img src={FarmLogo} className="logo" alt="Farm logo" />
</a>
<a href="https://react.dev" target="_blank" rel="noreferrer">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Farm + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>count is {count}</button>
<p>
Edit <code>src/main.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs" onClick={() => go('/about')}>
Go to about page
</p>
</>
);
}
// export default Index;
42 changes: 42 additions & 0 deletions examples/react-query/src/pages/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #9F1A8Faa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
16 changes: 16 additions & 0 deletions examples/react-query/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
declare module '*.svg';
declare module '*.png';
declare module '*.css';
declare module '~react-pages' {
import type { RouteObject } from 'react-router'

const routes: RouteObject[]
export default routes
}

declare module 'virtual:generated-pages-react' {
import type { RouteObject } from 'react-router'

const routes: RouteObject[]
export default routes
}
12 changes: 12 additions & 0 deletions examples/react-query/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"lib": ["DOM", "ES2017"],
"noEmit": true,
"esModuleInterop": true,
"jsx": "react",
"skipDefaultLibCheck": true,
"skipLibCheck": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
4 changes: 2 additions & 2 deletions packages/core/tests/binding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { test } from 'vitest';
import {
Compiler,
Logger,
UserConfig,
normalizeDevServerOptions,
normalizeUserCompilationConfig,
resolveMergedUserConfig,
UserConfig
resolveMergedUserConfig
} from '../src/index.js';

// just make sure the binding works
Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/common.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { fileURLToPath, pathToFileURL } from 'node:url';
import path from 'path';
import { Compiler } from '../src/compiler/index.js';
import { JsPlugin } from '../src/plugin/type.js';
import {
UserConfig,
normalizeUserCompilationConfig,
resolveMergedUserConfig,
UserConfig
resolveMergedUserConfig
} from '../src/config/index.js';
import { Logger } from '../src/index.js';
import { JsPlugin } from '../src/plugin/type.js';

export async function getCompiler(
root: string,
Expand Down
Loading

0 comments on commit d9cb690

Please sign in to comment.