Skip to content

Commit 0fe17fb

Browse files
authored
Rewrite ReactPy-Router (#30)
### Changed - Bump GitHub workflows - Rename `use_query` to `use_search_params`. - Rename `simple.router` to `browser_router`. - Rename `SimpleResolver` to `StarletteResolver`. - Rename `CONVERSION_TYPES` to `CONVERTERS`. - Change "Match Any" syntax from a star `*` to `{name:any}`. - Rewrite `reactpy_router.link` to be a server-side component. - Simplified top-level exports within `reactpy_router`. ### Added - New error for ReactPy router elements being used outside router context. - Configurable/inheritable `Resolver` base class. - Add debug log message for when there are no router matches. - Add slug as a supported type. ### Fixed - Fix bug where changing routes could cause render failure due to key identity. - Fix bug where "Match Any" pattern wouldn't work when used in complex or nested paths. - Fix bug where `link` elements could not have `@component` type children. - Fix bug where the ReactPy would not detect the current URL after a reconnection. - Fixed flakey tests on GitHub CI by adding click delays.
1 parent 0f4dea2 commit 0fe17fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1045
-1084
lines changed

Diff for: β€Ž.editorconfig

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
charset = utf-8
11+
end_of_line = lf
12+
13+
[*.py]
14+
indent_size = 4
15+
max_line_length = 120
16+
17+
[*.md]
18+
indent_size = 4
19+
20+
[*.html]
21+
max_line_length = off
22+
23+
[*.js]
24+
max_line_length = off
25+
26+
[*.css]
27+
indent_size = 4
28+
max_line_length = off
29+
30+
# Tests can violate line width restrictions in the interest of clarity.
31+
[**/test_*.py]
32+
max_line_length = off

Diff for: β€Ž.github/workflows/codeql.yml

+46-62
Original file line numberDiff line numberDiff line change
@@ -12,67 +12,51 @@
1212
name: "CodeQL"
1313

1414
on:
15-
push:
16-
branches: [ "main" ]
17-
pull_request:
18-
# The branches below must be a subset of the branches above
19-
branches: [ "main" ]
20-
schedule:
21-
# Runs at 22:21 on Monday.
22-
- cron: '21 22 * * 1'
15+
push:
16+
branches: ["main"]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: ["main"]
20+
schedule:
21+
# Runs at 22:21 on Monday.
22+
- cron: "21 22 * * 1"
2323

2424
jobs:
25-
analyze:
26-
name: Analyze
27-
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
28-
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
29-
permissions:
30-
actions: read
31-
contents: read
32-
security-events: write
33-
34-
strategy:
35-
fail-fast: false
36-
matrix:
37-
language: [ 'javascript', 'python' ]
38-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
39-
# Use only 'java' to analyze code written in Java, Kotlin or both
40-
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
41-
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
42-
43-
steps:
44-
- name: Checkout repository
45-
uses: actions/checkout@v3
46-
47-
# Initializes the CodeQL tools for scanning.
48-
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@v2
50-
with:
51-
languages: ${{ matrix.language }}
52-
# If you wish to specify custom queries, you can do so here or in a config file.
53-
# By default, queries listed here will override any specified in a config file.
54-
# Prefix the list here with "+" to use these queries and those in the config file.
55-
56-
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
57-
# queries: security-extended,security-and-quality
58-
59-
60-
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
61-
# If this step fails, then you should remove it and run the build manually (see below)
62-
- name: Autobuild
63-
uses: github/codeql-action/autobuild@v2
64-
65-
# ℹ️ Command-line programs to run using the OS shell.
66-
# πŸ“š See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
67-
68-
# If the Autobuild fails above, remove it and uncomment the following three lines.
69-
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
70-
71-
# - run: |
72-
# echo "Run, Build Application using script"
73-
# ./location_of_script_within_repo/buildscript.sh
74-
75-
- name: Perform CodeQL Analysis
76-
uses: github/codeql-action/analyze@v2
77-
with:
78-
category: "/language:${{matrix.language}}"
25+
analyze:
26+
name: Analyze
27+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
28+
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
29+
permissions:
30+
actions: read
31+
contents: read
32+
security-events: write
33+
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
language: ["javascript", "python"]
38+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
39+
# Use only 'java' to analyze code written in Java, Kotlin or both
40+
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
41+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
42+
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
47+
# Initializes the CodeQL tools for scanning.
48+
- name: Initialize CodeQL
49+
uses: github/codeql-action/init@v3
50+
with:
51+
languages: ${{ matrix.language }}
52+
# If you wish to specify custom queries, you can do so here or in a config file.
53+
# By default, queries listed here will override any specified in a config file.
54+
# Prefix the list here with "+" to use these queries and those in the config file.
55+
56+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
57+
# queries: security-extended,security-and-quality
58+
59+
- name: Perform CodeQL Analysis
60+
uses: github/codeql-action/analyze@v3
61+
with:
62+
category: "/language:${{matrix.language}}"

Diff for: β€Ž.github/workflows/publish-develop-docs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ jobs:
77
deploy:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4
1111
with:
1212
fetch-depth: 0
13-
- uses: actions/setup-python@v4
13+
- uses: actions/setup-python@v5
1414
with:
1515
python-version: 3.x
1616
- run: pip install -r requirements/build-docs.txt

Diff for: β€Ž.github/workflows/publish-py.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
publish-package:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
- name: Set up Python
16-
uses: actions/setup-python@v4
16+
uses: actions/setup-python@v5
1717
with:
1818
python-version: "3.x"
1919
- name: Install dependencies

Diff for: β€Ž.github/workflows/publish-release-docs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
deploy:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212
with:
1313
fetch-depth: 0
14-
- uses: actions/setup-python@v4
14+
- uses: actions/setup-python@v5
1515
with:
1616
python-version: 3.x
1717
- run: pip install -r requirements/build-docs.txt

Diff for: β€Ž.github/workflows/test-docs.yml

+34-32
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
name: Test
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
10-
schedule:
11-
- cron: "0 0 * * *"
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
schedule:
11+
- cron: "0 0 * * *"
1212

1313
jobs:
14-
docs:
15-
runs-on: ubuntu-latest
16-
steps:
17-
- uses: actions/checkout@v3
18-
with:
19-
fetch-depth: 0
20-
- uses: actions/setup-python@v4
21-
with:
22-
python-version: 3.x
23-
- name: Check docs build
24-
run: |
25-
pip install -r requirements/build-docs.txt
26-
linkcheckMarkdown docs/ -v -r
27-
linkcheckMarkdown README.md -v -r
28-
linkcheckMarkdown CHANGELOG.md -v -r
29-
cd docs
30-
mkdocs build --strict
31-
- name: Check docs examples
32-
run: |
33-
pip install -r requirements/check-types.txt
34-
pip install -r requirements/check-style.txt
35-
mypy --show-error-codes docs/examples/python/
36-
black docs/examples/python/ --check
37-
ruff check docs/examples/python/
14+
docs:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: 3.x
23+
- name: Install Python Dependencies
24+
run: |
25+
pip install -r requirements/build-docs.txt
26+
pip install -r requirements/check-types.txt
27+
pip install -r requirements/check-style.txt
28+
pip install -e .
29+
- name: Check docs build
30+
run: |
31+
linkcheckMarkdown docs/ -v -r
32+
linkcheckMarkdown README.md -v -r
33+
linkcheckMarkdown CHANGELOG.md -v -r
34+
cd docs
35+
mkdocs build --strict
36+
- name: Check docs examples
37+
run: |
38+
mypy --show-error-codes docs/examples/python/
39+
ruff check docs/examples/python/

Diff for: β€Ž.github/workflows/test-src.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
matrix:
1818
python-version: ["3.9", "3.10", "3.11"]
1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- name: Use Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v4
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: ${{ matrix.python-version }}
2525
- name: Install Python Dependencies
@@ -29,9 +29,9 @@ jobs:
2929
coverage:
3030
runs-on: ubuntu-latest
3131
steps:
32-
- uses: actions/checkout@v2
32+
- uses: actions/checkout@v4
3333
- name: Use Latest Python
34-
uses: actions/setup-python@v2
34+
uses: actions/setup-python@v5
3535
with:
3636
python-version: "3.10"
3737
- name: Install Python Dependencies

Diff for: β€Ž.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ docs/site
44

55
# --- JAVASCRIPT BUNDLES ---
66

7-
src/reactpy_router/bundle.js
7+
src/reactpy_router/static/bundle.js
88

99
# --- PYTHON IGNORE FILES ----
1010

@@ -108,7 +108,7 @@ celerybeat.pid
108108

109109
# Environments
110110
.env
111-
.venv
111+
.venv*
112112
env/
113113
venv/
114114
ENV/

Diff for: β€Ž.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"proseWrap": "never",
3+
"trailingComma": "all"
4+
}

Diff for: β€ŽCHANGELOG.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,31 @@ Using the following categories, list your changes in this order:
3434

3535
## [Unreleased]
3636

37-
- Nothing (yet)!
37+
### Changed
38+
39+
- Bump GitHub workflows
40+
- Rename `use_query` to `use_search_params`.
41+
- Rename `simple.router` to `browser_router`.
42+
- Rename `SimpleResolver` to `StarletteResolver`.
43+
- Rename `CONVERSION_TYPES` to `CONVERTERS`.
44+
- Change "Match Any" syntax from a star `*` to `{name:any}`.
45+
- Rewrite `reactpy_router.link` to be a server-side component.
46+
- Simplified top-level exports within `reactpy_router`.
47+
48+
### Added
49+
50+
- New error for ReactPy router elements being used outside router context.
51+
- Configurable/inheritable `Resolver` base class.
52+
- Add debug log message for when there are no router matches.
53+
- Add slug as a supported type.
54+
55+
### Fixed
56+
57+
- Fix bug where changing routes could cause render failure due to key identity.
58+
- Fix bug where "Match Any" pattern wouldn't work when used in complex or nested paths.
59+
- Fix bug where `link` elements could not have `@component` type children.
60+
- Fix bug where the ReactPy would not detect the current URL after a reconnection.
61+
- Fixed flakey tests on GitHub CI by adding click delays.
3862

3963
## [0.1.1] - 2023-12-13
4064

Diff for: β€ŽMANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include src/reactpy_router/bundle.js
1+
recursive-include src/reactpy_router/static *
22
include src/reactpy_router/py.typed

Diff for: β€Ždocs/examples/python/basic-routing-more-routes.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from reactpy import component, html, run
2-
3-
from reactpy_router import route, simple
2+
from reactpy_router import browser_router, route
43

54

65
@component
76
def root():
8-
return simple.router(
7+
return browser_router(
98
route("/", html.h1("Home Page 🏠")),
109
route("/messages", html.h1("Messages πŸ’¬")),
11-
route("*", html.h1("Missing Link πŸ”—β€πŸ’₯")),
10+
route("{404:any}", html.h1("Missing Link πŸ”—β€πŸ’₯")),
1211
)
1312

1413

Diff for: β€Ždocs/examples/python/basic-routing.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from reactpy import component, html, run
2-
3-
from reactpy_router import route, simple
2+
from reactpy_router import browser_router, route
43

54

65
@component
76
def root():
8-
return simple.router(
7+
return browser_router(
98
route("/", html.h1("Home Page 🏠")),
10-
route("*", html.h1("Missing Link πŸ”—β€πŸ’₯")),
9+
route("{404:any}", html.h1("Missing Link πŸ”—β€πŸ’₯")),
1110
)
1211

1312

0 commit comments

Comments
Β (0)