Skip to content

Commit

Permalink
Stopped bundling navigation react
Browse files Browse the repository at this point in the history
Can't bundle navigation react and support 'use client'. Bundling puts all components into a single file but 'use client' needs to be applied at the file level.
So switched the package task of navigation react to transpile using typescript instead of bundle using rollup. Kept rollup for all other libraries and tasks.
Without bundling typescript puts some helper stuff at the top of each file - it used appear just once when it was one big file. To keep this to a minimum removed 'import * as React from 'react';' - this isn't needed anymore because react/typescript adds 'react/jsx-runtime'. Removing this removes the importStar typescript helper stuff. Don't want to 'importHelpers' because then dependent on tslib and don't want any 3rd party dependencies.
This stopped the build task from working because it didn't recognise 'react/jsx-runtime'. So added it as an external but there is no umd build for it so the index.html sample won't work anymore. But noticed that [react doesn't support umd builds anymore](facebook/react#28735 (comment)) anyway so will either ditch the build task and index.html sample or switch to esm?! will investigate later.
Haven't tried the unbundled navigation react package but the files are generated at least
  • Loading branch information
grahammendick committed Jan 11, 2025
1 parent 75c867d commit c78c297
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build/dist
build/npm/**/navigation*.js
build/npm/**/*.js
build/npm/**/android
build/npm/**/ios
build/npm/**/cpp
Expand Down
2 changes: 1 addition & 1 deletion NavigationReact/src/FluentLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'
import LinkUtility from './LinkUtility';
import withStateNavigator from './withStateNavigator';
import { FluentLinkProps } from './Props';
import * as React from 'react';

var FluentLink = (props: FluentLinkProps) => {
var htmlProps = LinkUtility.toHtmlProps(props);
Expand Down
4 changes: 2 additions & 2 deletions NavigationReact/src/NavigationBackLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import LinkUtility from './LinkUtility';
'use client'
import LinkUtility from './LinkUtility';
import withStateNavigator from './withStateNavigator';
import { NavigationBackLinkProps } from './Props';
import * as React from 'react';

var NavigationBackLink = (props: NavigationBackLinkProps) => {
var htmlProps = LinkUtility.toHtmlProps(props);
Expand Down
4 changes: 2 additions & 2 deletions NavigationReact/src/NavigationContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext } from 'react';
import { StateNavigator } from 'navigation';
import * as React from 'react';

export default React.createContext({ oldState: null, state: null, data: {}, stateNavigator: new StateNavigator() });
export default createContext({ oldState: null, state: null, data: {}, stateNavigator: new StateNavigator() });
5 changes: 3 additions & 2 deletions NavigationReact/src/NavigationHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use client'
import { Component } from 'react';
import AsyncStateNavigator from './AsyncStateNavigator';
import NavigationContext from './NavigationContext';
import { StateNavigator, State } from 'navigation';
import * as React from 'react';
type NavigationHandlerState = { context: { oldState: State, state: State, data: any, asyncData: any, stateNavigator: AsyncStateNavigator } };

class NavigationHandler extends React.Component<{ stateNavigator: StateNavigator, children: any }, NavigationHandlerState> {
class NavigationHandler extends Component<{ stateNavigator: StateNavigator, children: any }, NavigationHandlerState> {
constructor(props) {
super(props);
var { stateNavigator } = this.props;
Expand Down
1 change: 0 additions & 1 deletion NavigationReact/src/NavigationLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import LinkUtility from './LinkUtility';
import withStateNavigator from './withStateNavigator';
import { NavigationLinkProps } from './Props';
import * as React from 'react';

var NavigationLink = (props: NavigationLinkProps) => {
var htmlProps = LinkUtility.toHtmlProps(props);
Expand Down
10 changes: 10 additions & 0 deletions NavigationReact/src/NavigationReact.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import AsyncStateNavigator from './AsyncStateNavigator';
import NavigationContext from './NavigationContext.server';
import NavigationHandler from './NavigationHandler';
import NavigationBackLink from './NavigationBackLink';
import NavigationLink from './NavigationLink';
import RefreshLink from './RefreshLink';
import FluentLink from './FluentLink';
import SceneView from './SceneView.server';

export { AsyncStateNavigator, NavigationContext, NavigationHandler, NavigationBackLink, NavigationLink, RefreshLink, FluentLink, SceneView };
4 changes: 2 additions & 2 deletions NavigationReact/src/RefreshLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import LinkUtility from './LinkUtility';
'use client'
import LinkUtility from './LinkUtility';
import withStateNavigator from './withStateNavigator';
import { RefreshLinkProps } from './Props';
import * as React from 'react';

var RefreshLink = (props: RefreshLinkProps) => {
var htmlProps = LinkUtility.toHtmlProps(props);
Expand Down
1 change: 0 additions & 1 deletion NavigationReact/src/SceneRSCView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const SceneRSCView = ({children}) => children;

export default SceneRSCView;
1 change: 0 additions & 1 deletion NavigationReact/src/SceneView.server.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { SceneViewProps } from './Props';
import useNavigationEvent from './useNavigationEvent';
import SceneRSCView from './SceneRSCView';
Expand Down
2 changes: 1 addition & 1 deletion NavigationReact/src/SceneView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import { useContext } from 'react';
import NavigationContext from './NavigationContext';
import { SceneViewProps } from './Props';

Expand Down
2 changes: 1 addition & 1 deletion NavigationReact/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"jsx": "react",
"jsx": "react-jsx",
"esModuleInterop": true,
"baseUrl": "../../types"
}
Expand Down
4 changes: 2 additions & 2 deletions NavigationReact/src/withStateNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import NavigationContext from './NavigationContext';
import * as React from 'react';
import { ComponentType } from 'react';
import { LinkProps } from './Props';

export default <T extends LinkProps>(Link: React.ComponentType<T>) => (props: T) => (
export default <T extends LinkProps>(Link: ComponentType<T>) => (props: T) => (
<NavigationContext.Consumer>
{({ stateNavigator }) => <Link {...props} stateNavigator={stateNavigator} />}
</NavigationContext.Consumer>
Expand Down
14 changes: 13 additions & 1 deletion build/npm/navigation-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@
"name": "navigation-react",
"version": "4.5.1",
"description": "React plugin for the Navigation router",
"main": "navigation.react.js",
"main": "NavigationReact.js",
"types": "navigation.react.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/grahammendick/navigation.git"
},
"exports": {
".": {
"react-server": {
"browser": "./NavigationReact.server.js",
"node": "./NavigationReact.server.js"
},
"default": {
"browser": "./NavigationReact.js",
"node": "./NavigationReact.js"
}
}
},
"keywords": [
"router",
"navigation",
Expand Down
21 changes: 17 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ var rename = require('gulp-rename');
var rollup = require('rollup');
var sucrase = require('@rollup/plugin-sucrase');
var terser = require('gulp-terser');
var ts = require('gulp-typescript');
var typescript = require('@rollup/plugin-typescript');

events.EventEmitter.defaultMaxListeners = 0;

var items = [
require('./build/npm/navigation/package.json'),
Object.assign({ globals: { navigation: 'Navigation', react: 'React',
'react-dom': 'ReactDOM' } },
'react-dom': 'ReactDOM', 'react/jsx-runtime': '_jsx' } },
require('./build/npm/navigation-react/package.json')),
Object.assign({ globals: { navigation: 'Navigation',
'navigation-react': 'NavigationReact', react: 'React' } },
Expand Down Expand Up @@ -97,9 +98,21 @@ var itemTasks = items.reduce((tasks, item) => {
var { globals = {}, format = 'cjs' } = item;
tasks.buildTasks.push(
nameFunc(() => buildTask(name, tsFrom, jsTo, globals, item), 'build' + name));
tasks.packageTasks.push(
nameFunc(() => rollupTask(name, tsFrom, jsPackageTo, globals, format), 'package' + name)
);
if (!item.exports) {
tasks.packageTasks.push(
nameFunc(() => rollupTask(name, tsFrom, jsPackageTo, globals, format), 'package' + name)
);
} else {
var include = tsFrom.replace(name + '.ts', '**/*.{ts,tsx}');
var tsconfig = tsFrom.replace(name + '.ts', 'tsconfig.json');
tasks.packageTasks.push(
nameFunc(() => (
src(include)
.pipe(ts.createProject(tsconfig)())
.pipe(dest(`./build/npm/${packageName}`))
), 'package' + name)
);
}
return tasks;
}, { buildTasks: [], packageTasks: [] });

Expand Down
163 changes: 163 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"gulp-mocha": "^8.0.0",
"gulp-rename": "^1.2.3",
"gulp-terser": "^1.2.0",
"gulp-typescript": "^6.0.0-alpha.1",
"jsdom": "^25.0.1",
"navigation": "file:build/npm/navigation",
"navigation-react": "file:build/npm/navigation-react",
Expand Down

0 comments on commit c78c297

Please sign in to comment.