From 7df33f32b5a4359a2daa41657b31fad1ffba2698 Mon Sep 17 00:00:00 2001 From: "maxime.batista" Date: Thu, 2 Nov 2023 18:27:49 +0100 Subject: [PATCH] apply suggestions --- Documentation/how-to-dev.md | 2 +- composer.json | 1 - package.json | 14 +------------- public/index.php | 4 ++-- src/Controller/SampleFormController.php | 2 +- src/react-display-file.php | 6 ++++-- 6 files changed, 9 insertions(+), 20 deletions(-) diff --git a/Documentation/how-to-dev.md b/Documentation/how-to-dev.md index 68599a2..88e9d75 100644 --- a/Documentation/how-to-dev.md +++ b/Documentation/how-to-dev.md @@ -144,7 +144,7 @@ function _asset(string $assetURI): string { Conventions regarding our react views __must be respected in order to be renderable__. ### The `render(any)` function -__any react view file__ should __export__ a function with signature `render(arguments: any)`, which responsibility is to render the view. +Any React view component needs to be default exported in order to be imported and used from PHP. Those components will receive as props the arguments that the PHP server has transmitted. The `arguments` parameter is used to pass data to the react component. If you take a look at the `front/views/SampleForm.tsx` view, here's the definition of its render function : diff --git a/composer.json b/composer.json index 664e469..7cfbb6b 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,6 @@ "App\\": "src/" } }, - "include-path": ["src"], "require": { "altorouter/altorouter": "1.2.0", "ext-json": "*" diff --git a/package.json b/package.json index 7f10a8c..5a18741 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@types/react-dom": "^18.2.14", "react": "^18.2.0", "react-dom": "^18.2.0", - "typescript": "^4.9.5", + "typescript": "^5.2.2", "vite": "^4.5.0", "web-vitals": "^2.1.4" }, @@ -27,18 +27,6 @@ "react-app/jest" ] }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - }, "devDependencies": { "@vitejs/plugin-react": "^4.1.0" } diff --git a/public/index.php b/public/index.php index 23830c0..23737f5 100644 --- a/public/index.php +++ b/public/index.php @@ -34,8 +34,8 @@ $match = $router->match(); if ($match == null) { // TODO redirect to a 404 not found page instead (issue #1) - echo "page non trouvée"; - header('HTTP/1.1 404 Not Found'); + http_response_code(404); + echo "Page non trouvée"; exit(1); } diff --git a/src/Controller/SampleFormController.php b/src/Controller/SampleFormController.php index 8a4faa7..5c4dfbd 100644 --- a/src/Controller/SampleFormController.php +++ b/src/Controller/SampleFormController.php @@ -2,7 +2,7 @@ namespace App\Controller; -require_once "react-display.php"; +require_once __DIR__ . "/../react-display.php"; class SampleFormController { public function displayForm() { diff --git a/src/react-display-file.php b/src/react-display-file.php index 6acb652..55d9656 100755 --- a/src/react-display-file.php +++ b/src/react-display-file.php @@ -10,11 +10,11 @@ RefreshRuntime.injectIntoGlobalHook(window) window.\$RefreshReg$ = () => {} window.\$RefreshSig$ = () => (type) => type + window.__vite_plugin_react_preamble_installed__ = true "; } ?> - window.__vite_plugin_react_preamble_installed__ = true "> @@ -24,7 +24,9 @@ Document - + + +